File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -363,4 +363,22 @@ int callCommand(void)
363
363
if (tmp == 1 ) // tmp could have been modified by the call.
364
364
return 1 ;
365
365
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
+ }
Original file line number Diff line number Diff line change 38
38
| PointlessComparison.c:303:9:303:14 | ... >= ... | Comparison is always false because c <= 0. |
39
39
| PointlessComparison.c:312:9:312:14 | ... >= ... | Comparison is always false because c <= 0. |
40
40
| 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. |
41
45
| RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. |
42
46
| Templates.cpp:9:10:9:24 | ... <= ... | Comparison is always true because local <= 32767. |
You can’t perform that action at this time.
0 commit comments