Skip to content

Commit 10bb7e4

Browse files
committed
Fix AlertReporting for nested macros
Nested macro invocations do not have getExpandedElements(), but do have getAffectedElements().
1 parent 0ff6f35 commit 10bb7e4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cpp/common/src/codingstandards/cpp/AlertReporting.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ module MacroUnwrapper<ResultType ResultElement> {
1414
* Gets a macro invocation that applies to the result element.
1515
*/
1616
private MacroInvocation getAMacroInvocation(ResultElement re) {
17-
result.getAnExpandedElement() = re
17+
result.getAnAffectedElement() = re
1818
}
1919

2020
/**
2121
* Gets the primary macro invocation that generated the result element.
22+
*
23+
* Does not hold for cases where the result element is located at a macro argument site.
2224
*/
2325
MacroInvocation getPrimaryMacroInvocation(ResultElement re) {
2426
exists(MacroInvocation mi |
2527
mi = getAMacroInvocation(re) and
28+
// Only report cases where the element is not located at the macro expansion site
29+
// This means we'll report results in macro arguments in the macro argument
30+
// location, not within the macro itself
31+
mi.getLocation().getStartColumn() = re.getLocation().getStartColumn() and
2632
// No other more specific macro that expands to element
2733
not exists(MacroInvocation otherMi |
2834
otherMi = getAMacroInvocation(re) and otherMi.getParentInvocation() = mi

0 commit comments

Comments
 (0)