Skip to content

Commit 33130b9

Browse files
committed
CPP: Apply recommended fix.
1 parent 6a14748 commit 33130b9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ from ComparisonOperation cmp
1818
where pointlessSelfComparison(cmp)
1919
and not nanTest(cmp)
2020
and not overflowTest(cmp)
21-
and not cmp.isInMacroExpansion()
21+
and not exists(MacroInvocation mi |
22+
// cmp is in mi
23+
mi.getAnExpandedElement() = cmp and
24+
25+
// and cmp was apparently not passed in as a macro parameter
26+
cmp.getLocation().getStartLine() = mi.getLocation().getStartLine() and
27+
cmp.getLocation().getStartColumn() = mi.getLocation().getStartColumn()
28+
)
2229
select cmp, "Self comparison."

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |
44
| test.cpp:90:10:90:15 | ... == ... | Self comparison. |
55
| test.cpp:118:7:118:32 | ... != ... | Self comparison. |
6+
| test.cpp:151:11:151:16 | ... == ... | Self comparison. |

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BadAdditionOverflowCheck/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ void useMarkRange(int offs) {
148148
#define MY_MACRO(x) (x)
149149

150150
void myMacroTest(int x) {
151-
MY_MACRO(x == x); // BAD [NOT DETECTED]
151+
MY_MACRO(x == x); // BAD
152152
}

0 commit comments

Comments
 (0)