Title: [229242] trunk/Source/WTF
Revision
229242
Author
[email protected]
Date
2018-03-05 03:12:57 -0800 (Mon, 05 Mar 2018)

Log Message

Unreviewed, fix MediaTime test
https://bugs.webkit.org/show_bug.cgi?id=183319

__builtin_xxx_overflow writes overflowed data into ResultType value even if overflow happens.
This is different from the original CheckedArithmetic semantics.

* wtf/CheckedArithmetic.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (229241 => 229242)


--- trunk/Source/WTF/ChangeLog	2018-03-05 11:10:53 UTC (rev 229241)
+++ trunk/Source/WTF/ChangeLog	2018-03-05 11:12:57 UTC (rev 229242)
@@ -1,3 +1,13 @@
+2018-03-05  Yusuke Suzuki  <[email protected]>
+
+        Unreviewed, fix MediaTime test
+        https://bugs.webkit.org/show_bug.cgi?id=183319
+
+        __builtin_xxx_overflow writes overflowed data into ResultType value even if overflow happens.
+        This is different from the original CheckedArithmetic semantics.
+
+        * wtf/CheckedArithmetic.h:
+
 2018-03-04  Yusuke Suzuki  <[email protected]>
 
         [WTF] Move currentCPUTime and sleep(Seconds) to CPUTime.h and Seconds.h respectively

Modified: trunk/Source/WTF/wtf/CheckedArithmetic.h (229241 => 229242)


--- trunk/Source/WTF/wtf/CheckedArithmetic.h	2018-03-05 11:10:53 UTC (rev 229241)
+++ trunk/Source/WTF/wtf/CheckedArithmetic.h	2018-03-05 11:12:57 UTC (rev 229242)
@@ -271,7 +271,11 @@
     static inline bool add(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_add_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_add_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         if (signsMatch(lhs, rhs)) {
             if (lhs >= 0) {
@@ -291,7 +295,11 @@
     static inline bool sub(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_sub_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_sub_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         if (!signsMatch(lhs, rhs)) {
             if (lhs >= 0) {
@@ -310,7 +318,11 @@
     static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_mul_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_mul_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         if (signsMatch(lhs, rhs)) {
             if (lhs >= 0) {
@@ -345,7 +357,11 @@
     static inline bool add(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_add_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_add_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         ResultType temp = lhs + rhs;
         if (temp < lhs)
@@ -358,7 +374,11 @@
     static inline bool sub(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_sub_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_sub_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         ResultType temp = lhs - rhs;
         if (temp > lhs)
@@ -371,7 +391,11 @@
     static inline bool multiply(LHS lhs, RHS rhs, ResultType& result) WARN_UNUSED_RETURN
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_mul_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_mul_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         if (!lhs || !rhs) {
             result = 0;
@@ -392,7 +416,11 @@
     static inline bool add(int64_t lhs, int64_t rhs, ResultType& result)
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_add_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_add_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         int64_t temp = lhs + rhs;
         if (temp < std::numeric_limits<ResultType>::min())
@@ -407,7 +435,11 @@
     static inline bool sub(int64_t lhs, int64_t rhs, ResultType& result)
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_sub_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_sub_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         int64_t temp = lhs - rhs;
         if (temp < std::numeric_limits<ResultType>::min())
@@ -422,7 +454,11 @@
     static inline bool multiply(int64_t lhs, int64_t rhs, ResultType& result)
     {
 #if COMPILER(GCC_OR_CLANG)
-        return !__builtin_mul_overflow(lhs, rhs, &result);
+        ResultType temp;
+        if (__builtin_mul_overflow(lhs, rhs, &temp))
+            return false;
+        result = temp;
+        return true;
 #else
         int64_t temp = lhs * rhs;
         if (temp < std::numeric_limits<ResultType>::min())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to