File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -285,3 +285,33 @@ int widening_cast2(u8 c) {
285285 else
286286 return 1 ;
287287}
288+
289+ int unsigned_implicit_conversion (unsigned int ui1 ) {
290+ // These two comparisons are supported by the range analysis because the
291+ // implicit signedness conversion is on the constants (0 and 5), not on the
292+ // variables (ui1).
293+ if (ui1 == 0 ) {
294+ if (ui1 >= 5 ) { // BAD
295+ return 1 ;
296+ }
297+ }
298+ return 0 ;
299+ }
300+
301+ int signedness_cast1 (u8 c ) {
302+ if ((signed char )c == 0 ) {
303+ if (c >= 5 ) { // BAD [NOT DETECTED]
304+ return 1 ;
305+ }
306+ }
307+ return 0 ;
308+ }
309+
310+ int signedness_cast2 (signed char c ) {
311+ if ((u8 )c == 0 ) {
312+ if (c >= 5 ) { // BAD [NOT DETECTED]
313+ return 1 ;
314+ }
315+ }
316+ return 0 ;
317+ }
Original file line number Diff line number Diff line change 3535| PointlessComparison.c:264:12:264:22 | ... >= ... | Comparison is always true because dbl >= 0 and -0 >= - .... |
3636| PointlessComparison.c:273:9:273:18 | ... > ... | Comparison is always false because c <= 0. |
3737| PointlessComparison.c:283:13:283:19 | ... >= ... | Comparison is always true because c >= 11. |
38+ | PointlessComparison.c:294:9:294:16 | ... >= ... | Comparison is always false because ui1 <= 0. |
3839| RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. |
3940| 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