Skip to content

Commit 0cbed34

Browse files
committed
[MERGE #5384 @sethbrenith] fix a warning about buffer bounds
Merge pull request #5384 from sethbrenith:user/sethb/prefast Tell the static analysis tool that UInt32Math::Add adds and guarantees no overflow. Fixes OS:18017387
2 parents 0e93c3a + 0206f59 commit 0cbed34

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/Common/Common/UInt32Math.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ class UInt32Math
111111
return AddMul<add,mul>(left, ::Math::DefaultOverflowPolicy);
112112
}
113113

114+
_When_(lhs + rhs < lhs, _Analysis_noreturn_)
115+
_Post_satisfies_(return == lhs + rhs)
114116
static uint32 Add(uint32 lhs, uint32 rhs)
115117
{
116-
return Add( lhs, rhs, ::Math::DefaultOverflowPolicy );
118+
uint32 result = Add( lhs, rhs, ::Math::DefaultOverflowPolicy );
119+
_Analysis_assume_(result == lhs + rhs);
120+
return result;
117121
}
118122

119123
static uint32 Mul(uint32 lhs, uint32 rhs)

0 commit comments

Comments
 (0)