@@ -46,17 +46,35 @@ class CrementEffect extends LocalSideEffect::Range {
46
46
CrementEffect ( ) { this instanceof CrementOperation }
47
47
}
48
48
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
+
49
68
from
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 ,
51
70
string sideEffectDesc
52
71
where
53
72
not isExcluded ( e , SideEffects4Package:: sideEffectsInArgumentsToUnsafeMacrosQuery ( ) ) and
54
73
sideEffect = getASideEffect ( e ) and
55
74
flm .getAnInvocation ( ) = mi and
56
75
not exists ( mi .getParentInvocation ( ) ) and
57
76
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
60
78
arg = mi .getExpandedArgument ( i ) and
61
79
(
62
80
sideEffect instanceof CrementEffect and
0 commit comments