Merge pull request #153 from r-barnes/richard/binary_fix

Make binary search overflow safe
This commit is contained in:
Adam Sawicki 2020-10-29 12:04:55 +01:00 committed by GitHub
commit 4dc4abfc31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4721,7 +4721,7 @@ static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, co
size_t down = 0, up = (end - beg);
while(down < up)
{
const size_t mid = (down + up) / 2;
const size_t mid = down + (up - down) / 2; // Overflow-safe midpoint calculation
if(cmp(*(beg+mid), key))
{
down = mid + 1;