diff --git a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql index df6648b5ff4..916f664c4fa 100644 --- a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql +++ b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql @@ -25,7 +25,8 @@ import UnsignedGEZero // // So to reduce the number of false positives, we do not report a result if // the comparison is in a macro expansion. Similarly for template -// instantiations, static asserts, non-type template arguments, and constexprs. +// instantiations, static asserts, non-type template arguments, enum constants, +// and constexprs. from ComparisonOperation cmp, SmallSide ss, float left, float right, boolean value, string reason where not cmp.isInMacroExpansion() and @@ -33,6 +34,7 @@ where not exists(StaticAssert s | s.getCondition() = cmp.getParent*()) and not exists(Declaration d | d.getATemplateArgument() = cmp.getParent*()) and not exists(Variable v | v.isConstexpr() | v.getInitializer().getExpr() = cmp.getParent*()) and + not exists(EnumConstant e | e.getInitializer().getExpr() = cmp.getParent*()) and not functionContainsDisabledCode(cmp.getEnclosingFunction()) and reachablePointlessComparison(cmp, left, right, value, ss) and // a comparison between an enum and zero is always valid because whether diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected index 55a27a7a0ad..6c273b985ee 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected @@ -50,5 +50,4 @@ | PointlessComparison.cpp:43:6:43:29 | ... >= ... | Comparison is always true because ... >> ... >= 140737488355327.5. | | PointlessComparison.cpp:44:6:44:28 | ... >= ... | Comparison is always true because ... >> ... >= 140737488355327.5. | | RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. | -| RegressionTests.cpp:165:9:165:33 | ... > ... | Comparison is always true because ... * ... >= 64. | | Templates.cpp:9:10:9:24 | ... <= ... | Comparison is always true because local <= 32767. | diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp index dab0d9b3a5b..0ba766eda1d 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp @@ -162,5 +162,5 @@ struct A_Struct { }; enum E { - E_e = sizeof(A_Struct) * 8 > 50 // GOOD [FALSE POSITIVE] + E_e = sizeof(A_Struct) * 8 > 50 // GOOD };