Skip to content

Commit 4b159fd

Browse files
committed
C++: Fix the suppression for alerts about enums
The suppression mechanism broke when I changed `relOpWithSwap` to take fully-converted expressions as parameters.
1 parent 04a48e9 commit 4b159fd

File tree

3 files changed

+2
-3
lines changed

3 files changed

+2
-3
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
// a comparison between an enum and zero is always valid because whether
3939
// the underlying type of an enum is signed is compiler-dependent
4040
not exists (Expr e, ConstantZero z
41-
| relOpWithSwap(cmp, e, z, _, _) and
41+
| relOpWithSwap(cmp, e.getFullyConverted(), z, _, _) and
4242
e.getUnderlyingType() instanceof Enum) and
4343

4444
// Construct a reason for the message. Something like: x >= 5 and 3 >= y.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ enum my_enum {
207207
};
208208

209209
int myFunction6(enum my_enum e) {
210-
if (e < 0) { // BAD
210+
if (e < 0) { // GOOD (suppressed because it's platform-dependent)
211211
return 1;
212212
}
213213
return 0;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
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:210:6:210:10 | ... < ... | Comparison is always false because e >= 0. |
3534
| PointlessComparison.c:264:12:264:22 | ... >= ... | Comparison is always true because dbl >= 0 and -0 >= - .... |
3635
| PointlessComparison.c:273:9:273:18 | ... > ... | Comparison is always false because c <= 0. |
3736
| PointlessComparison.c:283:13:283:19 | ... >= ... | Comparison is always true because c >= 11. |

0 commit comments

Comments
 (0)