From 457f2bf3b976eb51fca2a5b60688037c3d5927fa Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 5 Jul 2012 10:13:13 -0400 Subject: [PATCH] Bug 768538 - 1/2 - Fix undefined behavior in CheckedInt - r=jwalden --- mfbt/CheckedInt.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mfbt/CheckedInt.h b/mfbt/CheckedInt.h index 30303cbcda9..20e9176c650 100644 --- a/mfbt/CheckedInt.h +++ b/mfbt/CheckedInt.h @@ -678,11 +678,13 @@ inline CheckedInt operator OP(const CheckedInt &lhs, \ { \ T x = lhs.mValue; \ T y = rhs.mValue; \ - T result = x OP y; \ T isOpValid = detail::Is##NAME##Valid(x, y); \ - /* Help the compiler perform RVO (return value optimization). */ \ - return CheckedInt(result, \ - lhs.mIsValid && rhs.mIsValid && isOpValid); \ + if (isOpValid) { \ + T result = x OP y; \ + return CheckedInt(result, lhs.mIsValid && rhs.mIsValid); \ + } else { \ + return CheckedInt(T(0), false); \ + } \ } MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +)