22 * @name Undefined result of signed test for overflow
33 * @description Testing for overflow by adding a value to a variable
44 * to see if it "wraps around" works only for
5- * ` unsigned` integer values.
5+ * unsigned integer values.
66 * @kind problem
77 * @problem.severity warning
88 * @precision high
@@ -15,12 +15,12 @@ import cpp
1515private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1616private import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1717
18- from RelationalOperation ro , AddExpr add , VariableAccess va1 , VariableAccess va2
18+ from RelationalOperation ro , AddExpr add , Expr expr1 , Expr expr2
1919where
2020 ro .getAnOperand ( ) = add and
21- add .getAnOperand ( ) = va1 and
22- ro .getAnOperand ( ) = va2 and
23- globalValueNumber ( va1 ) = globalValueNumber ( va2 ) and
24- add .getType ( ) . getUnspecifiedType ( ) .( IntegralType ) .isSigned ( ) and
21+ add .getAnOperand ( ) = expr1 and
22+ ro .getAnOperand ( ) = expr2 and
23+ globalValueNumber ( expr1 ) = globalValueNumber ( expr2 ) and
24+ add .getUnspecifiedType ( ) .( IntegralType ) .isSigned ( ) and
2525 exprMightOverflowPositively ( add )
2626select ro , "Testing for signed overflow may produce undefined results."
0 commit comments