File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -241,3 +241,27 @@ void macroExpansionTest() {
241241 MAYBE_DO (x = 1 ); // GOOD (the problem is in the macro)
242242 MAYBE_DO (if (global_setting >= 0 ) {x = 2 ;}); // BAD (the problem is in the invocation)
243243}
244+
245+ int overeager_wraparound (unsigned int u32bound , unsigned long long u64bound ) {
246+ unsigned int u32idx ;
247+ unsigned long long u64idx ;
248+
249+ for (u32idx = 1 ; u32idx < u32bound ; u32idx ++ ) {
250+ if (u32idx == 0 ) // BAD [NOT DETECTED]
251+ return 0 ;
252+ }
253+
254+ for (u64idx = 1 ; u64idx < u64bound ; u64idx ++ ) {
255+ if (u64idx == 0 ) // BAD [NOT DETECTED]
256+ return 0 ;
257+ }
258+
259+ return 1 ;
260+ }
261+
262+ int negative_zero (double dbl ) {
263+ if (dbl >= 0 ) {
264+ return dbl >= - dbl ; // GOOD [FALSE POSITIVE]
265+ }
266+ return 0 ;
267+ }
Original file line number Diff line number Diff line change 3131| PointlessComparison.c:126:12:126:18 | ... >= ... | Comparison is always true because a >= 20. |
3232| PointlessComparison.c:129:12:129:16 | ... > ... | Comparison is always false because a <= 3. |
3333| PointlessComparison.c:197:7:197:11 | ... < ... | Comparison is always false because x >= 0. |
34+ | PointlessComparison.c:264:12:264:22 | ... >= ... | Comparison is always true because dbl >= 0 and -0 >= - .... |
3435| RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. |
3536| 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