Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5558922

Browse files
committed
[CPP-434] Drop the requirement that RHS not be cast to unsigned, since overflow occurs on LHS. Adjust test case.
1 parent 33cd6de commit 5558922

3 files changed

Lines changed: 5 additions & 9 deletions

File tree

cpp/ql/src/Likely Bugs/Arithmetic/SignedOverflowCheck.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ where
2525
add.getAnOperand() = va1 and
2626
ro.getAnOperand() = va2 and
2727
globalValueNumber(va1) = globalValueNumber(va2) and
28-
isSignedWithoutUnsignedCast(add) and
29-
isSignedWithoutUnsignedCast(va2)
28+
isSignedWithoutUnsignedCast(add)
3029
select ro, "Testing for signed overflow may produce undefined results."

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/SignedOverflowCheck/SignedOverflowCheck.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ int checkOverflow4(unsigned int ioff, C c) {
9494
return 1;
9595
}
9696

97-
#define AV_INPUT_BUFFER_PADDING_SIZE 64
98-
99-
int overflow12(int codecdata_length) {
100-
if(codecdata_length + AV_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length) { // GOOD
101-
return -1;
102-
}
103-
return 1;
97+
int overflow12(int n) {
98+
// not deleted by gcc or clang
99+
return (n + 32 <= (unsigned)n? -1: 1); // BAD
104100
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| SignedOverflowCheck.cpp:8:12:8:22 | ... < ... | Testing for signed overflow may produce undefined results. |
22
| SignedOverflowCheck.cpp:18:12:18:26 | ... < ... | Testing for signed overflow may produce undefined results. |
33
| SignedOverflowCheck.cpp:35:9:35:23 | ... < ... | Testing for signed overflow may produce undefined results. |
4+
| SignedOverflowCheck.cpp:99:10:99:30 | ... <= ... | Testing for signed overflow may produce undefined results. |

0 commit comments

Comments
 (0)