From 275cd657df645d9c6f2bb5c2ec7446fb84557edd Mon Sep 17 00:00:00 2001 From: "jianghua.yjh" Date: Tue, 8 Sep 2015 07:50:27 -0700 Subject: [PATCH] Fix a potential overflow of binary search BUG= Review URL: https://codereview.chromium.org/1314253006 Cr-Commit-Position: refs/heads/master@{#30638} --- src/list-inl.h | 2 +- src/objects-inl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/list-inl.h b/src/list-inl.h index 94ef14dba..5a247d5fd 100644 --- a/src/list-inl.h +++ b/src/list-inl.h @@ -250,7 +250,7 @@ int SortedListBSearch(const List& list, P cmp) { int low = 0; int high = list.length() - 1; while (low <= high) { - int mid = (low + high) / 2; + int mid = low + (high - low) / 2; T mid_elem = list[mid]; if (cmp(&mid_elem) > 0) { diff --git a/src/objects-inl.h b/src/objects-inl.h index ce8cfe745..42e8354fb 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -2793,7 +2793,7 @@ int BinarySearch(T* array, Name* name, int low, int high, int valid_entries, DCHECK(low <= high); while (low != high) { - int mid = (low + high) / 2; + int mid = low + (high - low) / 2; Name* mid_name = array->GetSortedKey(mid); uint32_t mid_hash = mid_name->Hash(); -- 2.34.1