Fix #15117 (MSBuild arithmetic intrinsics: signed overflow UB in Add/… · cppchecksolutions/cppcheck@b8b27a9 · GitHub
Skip to content

Commit b8b27a9

Browse files
authored
Fix #15117 (MSBuild arithmetic intrinsics: signed overflow UB in Add/Subtract/Multiply) (cppcheck-opensource#8938)
The $([MSBuild]::Add/Subtract/Multiply) intrinsics in applyMSBuildStaticFunction computed a+b, a-b and a*b directly on long long operands from the project file, so values like $([MSBuild]::Add(9223372036854775807, 1)) were signed-overflow UB (reported by -fsanitize=signed-integer-overflow). MSBuild evaluates these in .NET's unchecked context, so on overflow the result wraps. The arithmetic is now done on unsigned long long and cast back, which gives the same two's complement result without UB. Divide/Modulo of LLONG_MIN by -1 throw OverflowException in .NET, so those return the empty string with a debug message, the same as the existing division-by-zero handling. Regression tests added to testMSBuildStaticFunctions.
1 parent 37a06d2 commit b8b27a9

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎lib/importproject.cpp‎

Lines changed: 28 additions & 3 deletions

‎test/testimportproject.cpp‎

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)