Don't overflow when dealing with large segment numbers

Issue: #2311

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144182445
This commit is contained in:
olly 2017-01-11 02:28:03 -08:00 committed by Oliver Woodman
parent ce03b8c246
commit 444811c010

View file

@ -143,7 +143,7 @@ public abstract class SegmentBase {
} else {
// The high index cannot be unbounded. Identify the segment using binary search.
while (lowIndex <= highIndex) {
int midIndex = (lowIndex + highIndex) / 2;
int midIndex = lowIndex + (highIndex - lowIndex) / 2;
long midTimeUs = getSegmentTimeUs(midIndex);
if (midTimeUs < timeUs) {
lowIndex = midIndex + 1;