Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Unified Diff: src/hydrogen-dehoist.cc

Issue 1058533007: Fix a few potential integer negation overflows (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/hydrogen-dehoist.cc
diff --git a/src/hydrogen-dehoist.cc b/src/hydrogen-dehoist.cc
index 0c7a9b964fc9251c7ff2a33bcccf5196ced193dd..51dda37e8ded9315401e08421b2bc421b152bd55 100644
--- a/src/hydrogen-dehoist.cc
+++ b/src/hydrogen-dehoist.cc
@@ -27,17 +27,18 @@ static void DehoistArrayIndex(ArrayInstructionInterface* array_operation) {
}
if (!constant->HasInteger32Value()) return;
+ v8::base::internal::CheckedNumeric<int32_t> checked_value =
+ constant->Integer32Value();
int32_t sign = binary_operation->IsSub() ? -1 : 1;
- int32_t value = constant->Integer32Value() * sign;
- if (value < 0) return;
+ checked_value = checked_value * sign;
// Multiply value by elements size, bailing out on overflow.
int32_t elements_kind_size =
1 << ElementsKindToShiftSize(array_operation->elements_kind());
- v8::base::internal::CheckedNumeric<int32_t> multiply_result = value;
- multiply_result = multiply_result * elements_kind_size;
- if (!multiply_result.IsValid()) return;
- value = multiply_result.ValueOrDie();
+ checked_value = checked_value * elements_kind_size;
+ if (!checked_value.IsValid()) return;
+ int32_t value = checked_value.ValueOrDie();
+ if (value < 0) return;
// Ensure that the array operation can add value to existing base offset
// without overflowing.

Powered by Google App Engine
This is Rietveld 408576698