diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index 56a590146567..863943dda9ab 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -216,7 +216,7 @@ TokenStream::SourceCoords::lineIndexOf(uint32_t offset) const // want one before that. iMax = lineStartOffsets_.length() - 2; while (iMax > iMin) { - iMid = (iMin + iMax) / 2; + iMid = iMin + (iMax - iMin) / 2; if (offset >= lineStartOffsets_[iMid + 1]) iMin = iMid + 1; // offset is above lineStartOffsets_[iMid] else diff --git a/js/src/jit/BaselineJIT.cpp b/js/src/jit/BaselineJIT.cpp index 6c4ef80807b3..bf6056da0b66 100644 --- a/js/src/jit/BaselineJIT.cpp +++ b/js/src/jit/BaselineJIT.cpp @@ -467,14 +467,14 @@ BaselineScript::maybeICEntryFromReturnOffset(CodeOffsetLabel returnOffset) { size_t bottom = 0; size_t top = numICEntries(); - size_t mid = (bottom + top) / 2; + size_t mid = bottom + (top - bottom) / 2; while (mid < top) { ICEntry &midEntry = icEntry(mid); if (midEntry.returnOffset().offset() < returnOffset.offset()) bottom = mid + 1; else // if (midEntry.returnOffset().offset() >= returnOffset.offset()) top = mid; - mid = (bottom + top) / 2; + mid = bottom + (top - bottom) / 2; } if (mid >= numICEntries()) return NULL; @@ -506,7 +506,7 @@ BaselineScript::icEntryFromPCOffset(uint32_t pcOffset) // those which have isForOp() set. size_t bottom = 0; size_t top = numICEntries(); - size_t mid = (bottom + top) / 2; + size_t mid = bottom + (top - bottom) / 2; while (mid < top) { ICEntry &midEntry = icEntry(mid); if (midEntry.pcOffset() < pcOffset) @@ -515,7 +515,7 @@ BaselineScript::icEntryFromPCOffset(uint32_t pcOffset) top = mid; else break; - mid = (bottom + top) / 2; + mid = bottom + (top - bottom) / 2; } // Found an IC entry with a matching PC offset. Search backward, and then // forward from this IC entry, looking for one with the same PC offset which diff --git a/js/src/jsinferinlines.h b/js/src/jsinferinlines.h index af6791dba80b..edd99090ce9a 100644 --- a/js/src/jsinferinlines.h +++ b/js/src/jsinferinlines.h @@ -720,7 +720,7 @@ TypeScript::BytecodeTypes(JSScript *script, jsbytecode *pc) // Fall back to a binary search. size_t bottom = 0; size_t top = script->nTypeSets - 1; - size_t mid = (bottom + top) / 2; + size_t mid = bottom + (top - bottom) / 2; while (mid < top) { if (bytecodeMap[mid] < offset) bottom = mid + 1; @@ -728,7 +728,7 @@ TypeScript::BytecodeTypes(JSScript *script, jsbytecode *pc) top = mid; else break; - mid = (bottom + top) / 2; + mid = bottom + (top - bottom) / 2; } // We should have have zeroed in on either the exact offset, unless there