diff options
author | Matt Stancliff <matt@genges.com> | 2014-08-01 13:01:33 -0400 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-08-07 16:17:37 +0200 |
commit | c82e0b701f86989711988dae8be97bdbe63395ba (patch) | |
tree | 4e7309588dd309453c6ad07ee39a2529ac61a53c /src/intset.c | |
parent | 87815ab5ba305770c0e6de7995b1688e55602589 (diff) | |
download | redis-c82e0b701f86989711988dae8be97bdbe63395ba.tar.gz |
Fix intset midpoint selection
The classic (min+max)/2 is provably unsafe. Fixed
as recommended in research:
http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
Fix inspired by @wjin, but I used a different approach.
(later, I found @kuebler fixed the same issue too).
Fixes #1741, #1602
Diffstat (limited to 'src/intset.c')
-rw-r--r-- | src/intset.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/intset.c b/src/intset.c index b61530e45..5d894e3cd 100644 --- a/src/intset.c +++ b/src/intset.c @@ -133,7 +133,7 @@ static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) { } while(max >= min) { - mid = (min+max)/2; + mid = ((unsigned int)min + (unsigned int)max) >> 1; cur = _intsetGet(is,mid); if (value > cur) { min = mid+1; |