@@ -46,17 +46,35 @@ class CrementEffect extends LocalSideEffect::Range {
4646 CrementEffect ( ) { this instanceof CrementOperation }
4747}
4848
49+ /**
50+ * A macro that is considered potentially "unsafe" because one or more arguments are expanded
51+ * multiple times.
52+ */
53+ class UnsafeMacro extends FunctionLikeMacro {
54+ int unsafeArgumentIndex ;
55+
56+ UnsafeMacro ( ) {
57+ exists ( this .getAParameterUse ( unsafeArgumentIndex ) ) and
58+ // Only consider arguments that are expanded multiple times, and do not consider "stringified" arguments
59+ count ( int indexInBody |
60+ indexInBody = this .getAParameterUse ( unsafeArgumentIndex ) and
61+ not this .getBody ( ) .charAt ( indexInBody ) = "#"
62+ ) > 1
63+ }
64+
65+ int getAnUnsafeArgumentIndex ( ) { result = unsafeArgumentIndex }
66+ }
67+
4968from
50- FunctionLikeMacro flm , MacroInvocation mi , Expr e , SideEffect sideEffect , int i , string arg ,
69+ UnsafeMacro flm , MacroInvocation mi , Expr e , SideEffect sideEffect , int i , string arg ,
5170 string sideEffectDesc
5271where
5372 not isExcluded ( e , SideEffects4Package:: sideEffectsInArgumentsToUnsafeMacrosQuery ( ) ) and
5473 sideEffect = getASideEffect ( e ) and
5574 flm .getAnInvocation ( ) = mi and
5675 not exists ( mi .getParentInvocation ( ) ) and
5776 mi .getAnExpandedElement ( ) = e and
58- // Only consider arguments that are expanded multiple times, and do not consider "stringified" arguments
59- count ( int index | index = flm .getAParameterUse ( i ) and not flm .getBody ( ) .charAt ( index ) = "#" ) > 1 and
77+ i = flm .getAnUnsafeArgumentIndex ( ) and
6078 arg = mi .getExpandedArgument ( i ) and
6179 (
6280 sideEffect instanceof CrementEffect and
0 commit comments