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

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

Issue 417353002: Fix a potential overflow in BinarySearch, same as Issue 344513004 (Closed) Base URL: https://github.com/v8/v8.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | 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 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 // there are three entries in this array it should be called with low=0 and 2758 // there are three entries in this array it should be called with low=0 and
2759 // high=2. 2759 // high=2.
2760 template<SearchMode search_mode, typename T> 2760 template<SearchMode search_mode, typename T>
2761 int BinarySearch(T* array, Name* name, int low, int high, int valid_entries) { 2761 int BinarySearch(T* array, Name* name, int low, int high, int valid_entries) {
2762 uint32_t hash = name->Hash(); 2762 uint32_t hash = name->Hash();
2763 int limit = high; 2763 int limit = high;
2764 2764
2765 ASSERT(low <= high); 2765 ASSERT(low <= high);
2766 2766
2767 while (low != high) { 2767 while (low != high) {
2768 int mid = (low + high) / 2; 2768 int mid = low + (high - low) / 2;
2769 Name* mid_name = array->GetSortedKey(mid); 2769 Name* mid_name = array->GetSortedKey(mid);
2770 uint32_t mid_hash = mid_name->Hash(); 2770 uint32_t mid_hash = mid_name->Hash();
2771 2771
2772 if (mid_hash >= hash) { 2772 if (mid_hash >= hash) {
2773 high = mid; 2773 high = mid;
2774 } else { 2774 } else {
2775 low = mid + 1; 2775 low = mid + 1;
2776 } 2776 }
2777 } 2777 }
2778 2778
(...skipping 4446 matching lines...) Expand 10 before | Expand all | Expand 10 after
7225 #undef READ_SHORT_FIELD 7225 #undef READ_SHORT_FIELD
7226 #undef WRITE_SHORT_FIELD 7226 #undef WRITE_SHORT_FIELD
7227 #undef READ_BYTE_FIELD 7227 #undef READ_BYTE_FIELD
7228 #undef WRITE_BYTE_FIELD 7228 #undef WRITE_BYTE_FIELD
7229 #undef NOBARRIER_READ_BYTE_FIELD 7229 #undef NOBARRIER_READ_BYTE_FIELD
7230 #undef NOBARRIER_WRITE_BYTE_FIELD 7230 #undef NOBARRIER_WRITE_BYTE_FIELD
7231 7231
7232 } } // namespace v8::internal 7232 } } // namespace v8::internal
7233 7233
7234 #endif // V8_OBJECTS_INL_H_ 7234 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698