Fix possible integer overflow in SkTSearch's midpoint calculation

Probably unlikely to matter in practice, but SkTQSort calculates its
midpoint correctly, so we might as well do it here too.  For more
background, see Joshua Bloch's "Nearly All Binary Searches and
Mergesorts are Broken" post:
http://googleresearch.blogspot.ru/2006/06/extra-extra-read-all-about-it-nearly.html

This doesn't change any public API.
TBR=reed@google.com

Review URL: https://codereview.chromium.org/1362613002
This commit is contained in:
mdempsky 2015-09-22 10:32:02 -07:00 committed by Commit bot
parent e73f1f6dfa
commit 07ed41fa40

View File

@ -49,7 +49,7 @@ int SkTSearch(const T base[], int count, const K& key, size_t elemSize, LESS& le
int hi = count - 1;
while (lo < hi) {
int mid = (hi + lo) >> 1;
int mid = lo + ((hi - lo) >> 1);
const T* elem = (const T*)((const char*)base + mid * elemSize);
if (less(*elem, key))