mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Merge pull request #16988 from MathiasVP/unsigned-difference-compares-eq-zero-fp-fixes
C++: Fix FPs in `cpp/unsigned-difference-expression-compared-zero`
This commit is contained in:
@@ -14,3 +14,4 @@
|
||||
| test.cpp:276:11:276:19 | ... > ... | Unsigned subtraction can never be negative. |
|
||||
| test.cpp:288:10:288:18 | ... > ... | Unsigned subtraction can never be negative. |
|
||||
| test.cpp:312:9:312:25 | ... > ... | Unsigned subtraction can never be negative. |
|
||||
| test.cpp:362:8:362:16 | ... > ... | Unsigned subtraction can never be negative. |
|
||||
|
||||
@@ -321,3 +321,57 @@ void test19() {
|
||||
total += get_data();
|
||||
}
|
||||
}
|
||||
|
||||
void test20(int a, bool b, unsigned long c)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if(b) {
|
||||
x = (a - c) / 2;
|
||||
} else {
|
||||
x = a - c;
|
||||
}
|
||||
|
||||
if (a - c - x > 0) // GOOD
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t get_uint32();
|
||||
int64_t get_int64();
|
||||
|
||||
void test21(unsigned long a)
|
||||
{
|
||||
{
|
||||
int b = a & get_int64();
|
||||
if (a - b > 0) { } // GOOD
|
||||
}
|
||||
|
||||
{
|
||||
int b = a - get_uint32();
|
||||
if(a - b > 0) { } // GOOD
|
||||
}
|
||||
|
||||
{
|
||||
int64_t c = get_int64();
|
||||
if(c <= 0) {
|
||||
int64_t b = (int64_t)a + c;
|
||||
if(a - b > 0) { } // GOOD
|
||||
}
|
||||
int64_t b = (int64_t)a + c;
|
||||
if(a - b > 0) { } // BAD
|
||||
}
|
||||
|
||||
{
|
||||
unsigned c = get_uint32();
|
||||
if(c >= 1) {
|
||||
int b = a / c;
|
||||
if(a - b > 0) { } // GOOD
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int b = a >> get_uint32();
|
||||
if(a - b > 0) { } // GOOD
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user