Skip to content

Commit 983acf2

Browse files
committed
C++: Add more FPs.
1 parent 68e3be1 commit 983acf2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@
1414
| test.cpp:276:11:276:19 | ... > ... | Unsigned subtraction can never be negative. |
1515
| test.cpp:288:10:288:18 | ... > ... | Unsigned subtraction can never be negative. |
1616
| test.cpp:312:9:312:25 | ... > ... | Unsigned subtraction can never be negative. |
17+
| test.cpp:347:9:347:17 | ... > ... | Unsigned subtraction can never be negative. |
18+
| test.cpp:352:6:352:14 | ... > ... | Unsigned subtraction can never be negative. |
19+
| test.cpp:359:10:359:18 | ... > ... | Unsigned subtraction can never be negative. |
20+
| test.cpp:362:8:362:16 | ... > ... | Unsigned subtraction can never be negative. |
21+
| test.cpp:369:10:369:18 | ... > ... | Unsigned subtraction can never be negative. |
22+
| test.cpp:375:8:375:16 | ... > ... | Unsigned subtraction can never be negative. |

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,43 @@ void test20(int a, bool b, unsigned long c)
335335
if (a - c - x > 0) // GOOD
336336
{
337337
}
338+
}
339+
340+
uint32_t get_uint32();
341+
int64_t get_int64();
342+
343+
void test21(unsigned long a)
344+
{
345+
{
346+
int b = a & get_int64();
347+
if (a - b > 0) { } // GOOD [FALSE POSITIVE]
348+
}
349+
350+
{
351+
int b = a - get_uint32();
352+
if(a - b > 0) { } // GOOD [FALSE POSITIVE]
353+
}
354+
355+
{
356+
int64_t c = get_int64();
357+
if(c <= 0) {
358+
int64_t b = (int64_t)a + c;
359+
if(a - b > 0) { } // GOOD [FALSE POSITIVE]
360+
}
361+
int64_t b = (int64_t)a + c;
362+
if(a - b > 0) { } // BAD
363+
}
364+
365+
{
366+
unsigned c = get_uint32();
367+
if(c >= 1) {
368+
int b = a / c;
369+
if(a - b > 0) { } // GOOD [FALSE POSITIVE]
370+
}
371+
}
372+
373+
{
374+
int b = a >> get_uint32();
375+
if(a - b > 0) { } // GOOD [FALSE POSITIVE]
376+
}
338377
}

0 commit comments

Comments
 (0)