Skip to content

Commit c852452

Browse files
committed
C++: Add test cases.
1 parent b2f1008 commit c852452

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,22 @@ int callCommand(void)
363363
if (tmp == 1) // tmp could have been modified by the call.
364364
return 1;
365365
return 0;
366-
}
366+
}
367+
368+
int shifts(void)
369+
{
370+
unsigned int x = 3;
371+
372+
if (x >> 1 >= 1) {} // always true [BAD MESSAGE]
373+
if (x >> 1 >= 2) {} // always false [BAD MESSAGE]
374+
if (x >> 1 == 1) {} // always true [INCORRECT MESSAGE]
375+
}
376+
377+
int bitwise_ands()
378+
{
379+
unsigned int x = 0xFF;
380+
381+
if ((x & 2) >= 1) {}
382+
if ((x & 2) >= 2) {}
383+
if ((x & 2) >= 3) {} // always false
384+
}

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@
3838
| PointlessComparison.c:303:9:303:14 | ... >= ... | Comparison is always false because c <= 0. |
3939
| PointlessComparison.c:312:9:312:14 | ... >= ... | Comparison is always false because c <= 0. |
4040
| PointlessComparison.c:337:14:337:21 | ... >= ... | Comparison is always true because x >= 0. |
41+
| PointlessComparison.c:372:6:372:16 | ... >= ... | Comparison is always true because ... >> ... >= 1.5. |
42+
| PointlessComparison.c:373:6:373:16 | ... >= ... | Comparison is always false because ... >> ... <= 1.5. |
43+
| PointlessComparison.c:374:6:374:16 | ... == ... | Comparison is always false because ... >> ... >= 1.5. |
44+
| PointlessComparison.c:383:6:383:17 | ... >= ... | Comparison is always false because ... & ... <= 2. |
4145
| RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. |
4246
| Templates.cpp:9:10:9:24 | ... <= ... | Comparison is always true because local <= 32767. |

0 commit comments

Comments
 (0)