mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
[CPP-434] Incremental changes to SignedOverflowCheck.cpp test suite.
This commit is contained in:
@@ -32,14 +32,14 @@ bool shortShort1(unsigned short n1, unsigned short delta) {
|
||||
// clang 8.0.0 -O2: deleted
|
||||
// gcc 9.2 -O2: deleted
|
||||
// msvc 19.22 /O2: not deleted
|
||||
return n1 + delta < n1; // BAD
|
||||
return n1 + delta < n1; // BAD: will always be false
|
||||
}
|
||||
|
||||
bool shortShort2(unsigned short n1, unsigned short delta) {
|
||||
// clang 8.0.0 -O2: not deleted
|
||||
// gcc 9.2 -O2: not deleted
|
||||
// msvc 19.22 /O2: not deleted
|
||||
return (unsigned short)(n1 + delta) < n1; // BAD: n1 + delta overflow undefined
|
||||
return (unsigned short)(n1 + delta) < n1; // GOOD
|
||||
}
|
||||
|
||||
/* Distinguish `varname` from `ptr->varname` and `obj.varname` */
|
||||
@@ -110,9 +110,14 @@ bool multipleCasts2(char x) {
|
||||
// clang 9.0.0 -O2: not deleted
|
||||
// gcc 9.2 -O2: not deleted
|
||||
// msvc 19.22 /O2: not deleted
|
||||
return (int)(unsigned short)(x + '1') < (int)(unsigned short)x; // GOOD [FALSE POSITIVE]
|
||||
return (int)(unsigned short)(x + '1') < (int)(unsigned short)x; // BAD
|
||||
}
|
||||
|
||||
int does_it_overflow(int n1, unsigned short delta) {
|
||||
return n1 + (unsigned)delta < n1; // GOOD
|
||||
}
|
||||
|
||||
int overflow12b(int n) {
|
||||
// not deleted by gcc or clang
|
||||
return ((unsigned)(n + 32) <= (unsigned)n? -1: 1); // BAD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user