File tree Expand file tree Collapse file tree
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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. |
You can’t perform that action at this time.
0 commit comments