@@ -23,10 +23,11 @@ import semmle.code.cpp.valuenumbering.HashCons
23
23
class FunctionCallEffect extends GlobalSideEffect:: Range {
24
24
FunctionCallEffect ( ) {
25
25
exists ( Function f |
26
+ // Capture function calls as side-effects
26
27
f = this .( FunctionCall ) .getTarget ( ) and
27
- // Not a side-effecting function
28
+ // Excluding __builtin_expect, which is not a side-effecting function
28
29
not f .( BuiltInFunction ) .getName ( ) = "__builtin_expect" and
29
- // Not side-effecting functions
30
+ // Excluding common math functions
30
31
not exists ( string name |
31
32
name =
32
33
[
@@ -80,13 +81,20 @@ class UnsafeMacroInvocation extends MacroInvocation {
80
81
SideEffect getSideEffectForUnsafeArg ( int index ) {
81
82
index = this .getMacro ( ) .( UnsafeMacro ) .getAnUnsafeArgumentIndex ( ) and
82
83
exists ( Expr e , string arg |
83
- arg = this .getExpandedArgument ( index ) and
84
84
e = this .getAnExpandedElement ( ) and
85
85
result = getASideEffect ( e ) and
86
+ // Unfortunately, there's no semantic way to check whether a particular expression or
87
+ // side-effect generated by a macro came from a particular macro argument. The only
88
+ // information we get is the string of the expanded argument. We therefore do some basic
89
+ // string matching to check whether it looks like this side-effect comes from the given
90
+ // argument
91
+ arg = this .getExpandedArgument ( index ) and
86
92
(
93
+ // If this is a crement effect, then check that the text of the macro argument includes -- or ++
87
94
result instanceof CrementEffect and
88
95
exists ( arg .indexOf ( result .( CrementOperation ) .getOperator ( ) ) )
89
96
or
97
+ // If this is a functional call effect, then check that the text of the macro argument includes a call to that function
90
98
result instanceof FunctionCallEffect and
91
99
exists ( arg .indexOf ( result .( FunctionCall ) .getTarget ( ) .getName ( ) + "(" ) )
92
100
)
0 commit comments