Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: src/objects-inl.h

Issue 1314253006: Fix a potential overflow of binary search (Closed) Base URL: git@github.com:v8/v8-git-mirror.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/list-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 template <SearchMode search_mode, typename T> 2777 template <SearchMode search_mode, typename T>
2778 int BinarySearch(T* array, Name* name, int low, int high, int valid_entries, 2778 int BinarySearch(T* array, Name* name, int low, int high, int valid_entries,
2779 int* out_insertion_index) { 2779 int* out_insertion_index) {
2780 DCHECK(search_mode == ALL_ENTRIES || out_insertion_index == NULL); 2780 DCHECK(search_mode == ALL_ENTRIES || out_insertion_index == NULL);
2781 uint32_t hash = name->Hash(); 2781 uint32_t hash = name->Hash();
2782 int limit = high; 2782 int limit = high;
2783 2783
2784 DCHECK(low <= high); 2784 DCHECK(low <= high);
2785 2785
2786 while (low != high) { 2786 while (low != high) {
2787 int mid = (low + high) / 2; 2787 int mid = low + (high - low) / 2;
2788 Name* mid_name = array->GetSortedKey(mid); 2788 Name* mid_name = array->GetSortedKey(mid);
2789 uint32_t mid_hash = mid_name->Hash(); 2789 uint32_t mid_hash = mid_name->Hash();
2790 2790
2791 if (mid_hash >= hash) { 2791 if (mid_hash >= hash) {
2792 high = mid; 2792 high = mid;
2793 } else { 2793 } else {
2794 low = mid + 1; 2794 low = mid + 1;
2795 } 2795 }
2796 } 2796 }
2797 2797
(...skipping 5088 matching lines...) Expand 10 before | Expand all | Expand 10 after
7886 #undef READ_INT64_FIELD 7886 #undef READ_INT64_FIELD
7887 #undef WRITE_INT64_FIELD 7887 #undef WRITE_INT64_FIELD
7888 #undef READ_BYTE_FIELD 7888 #undef READ_BYTE_FIELD
7889 #undef WRITE_BYTE_FIELD 7889 #undef WRITE_BYTE_FIELD
7890 #undef NOBARRIER_READ_BYTE_FIELD 7890 #undef NOBARRIER_READ_BYTE_FIELD
7891 #undef NOBARRIER_WRITE_BYTE_FIELD 7891 #undef NOBARRIER_WRITE_BYTE_FIELD
7892 7892
7893 } } // namespace v8::internal 7893 } } // namespace v8::internal
7894 7894
7895 #endif // V8_OBJECTS_INL_H_ 7895 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/list-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698