Skip to content

Commit a8193da

Browse files
committed
C++: Reintroduce the exprMightOverflowNegatively bit.
1 parent 60e4fab commit a8193da

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

cpp/ql/src/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ where
7272
ro.getLesserOperand().getValue().toInt() = 0 and
7373
ro.getGreaterOperand() = sub and
7474
sub.getFullyConverted().getUnspecifiedType().(IntegralType).isUnsigned() and
75-
not exprIsSubLeftOrLess(sub, sub.getRightOperand())
75+
exprMightOverflowNegatively(sub.getFullyConverted()) and // generally catches false positives involving constants
76+
not exprIsSubLeftOrLess(sub, sub.getRightOperand()) // generally catches false positives where there's a relation between the left and right operands
7677
select ro, "Unsigned subtraction can never be negative."

cpp/ql/test/query-tests/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero/UnsignedDifferenceExpressionComparedZero.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
| test.cpp:182:6:182:14 | ... > ... | Unsigned subtraction can never be negative. |
1717
| test.cpp:195:6:195:14 | ... > ... | Unsigned subtraction can never be negative. |
1818
| test.cpp:208:6:208:14 | ... > ... | Unsigned subtraction can never be negative. |
19-
| test.cpp:241:10:241:18 | ... > ... | Unsigned subtraction can never be negative. |
2019
| test.cpp:252:10:252:18 | ... > ... | Unsigned subtraction can never be negative. |
2120
| test.cpp:266:10:266:24 | ... > ... | Unsigned subtraction can never be negative. |

cpp/ql/test/query-tests/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ int test13() {
238238
return 0;
239239
}
240240

241-
return (a - b > 0); // GOOD (as b = 0) [FALSE POSITIVE]
241+
return (a - b > 0); // GOOD (as b = 0)
242242
}
243243

244244
int test14() {

0 commit comments

Comments
 (0)