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:
Mathias Vorreiter Pedersen
2024-07-17 11:39:17 +01:00
committed by GitHub
4 changed files with 156 additions and 33 deletions

View File

@@ -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. |

View File

@@ -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
}
}