Explorar o código

Tell the static analysis tool that UInt32Math::Add adds and guarantees no overflow.

Fixes OS:18017387
Seth Brenith %!s(int64=7) %!d(string=hai) anos
pai
achega
0206f59b88
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      lib/Common/Common/UInt32Math.h

+ 5 - 1
lib/Common/Common/UInt32Math.h

@@ -111,9 +111,13 @@ public:
         return AddMul<add,mul>(left, ::Math::DefaultOverflowPolicy);
     }
 
+    _When_(lhs + rhs < lhs, _Analysis_noreturn_)
+    _Post_satisfies_(return == lhs + rhs)
     static uint32 Add(uint32 lhs, uint32 rhs)
     {
-        return Add( lhs, rhs, ::Math::DefaultOverflowPolicy );
+        uint32 result = Add( lhs, rhs, ::Math::DefaultOverflowPolicy );
+        _Analysis_assume_(result == lhs + rhs);
+        return result;
     }
 
     static uint32 Mul(uint32 lhs, uint32 rhs)