@@ -23,10 +23,11 @@ import semmle.code.cpp.valuenumbering.HashCons
2323class FunctionCallEffect extends GlobalSideEffect:: Range {
2424 FunctionCallEffect ( ) {
2525 exists ( Function f |
26+ // Capture function calls as side-effects
2627 f = this .( FunctionCall ) .getTarget ( ) and
27- // Not a side-effecting function
28+ // Excluding __builtin_expect, which is not a side-effecting function
2829 not f .( BuiltInFunction ) .getName ( ) = "__builtin_expect" and
29- // Not side-effecting functions
30+ // Excluding common math functions
3031 not exists ( string name |
3132 name =
3233 [
@@ -80,13 +81,20 @@ class UnsafeMacroInvocation extends MacroInvocation {
8081 SideEffect getSideEffectForUnsafeArg ( int index ) {
8182 index = this .getMacro ( ) .( UnsafeMacro ) .getAnUnsafeArgumentIndex ( ) and
8283 exists ( Expr e , string arg |
83- arg = this .getExpandedArgument ( index ) and
8484 e = this .getAnExpandedElement ( ) and
8585 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
8692 (
93+ // If this is a crement effect, then check that the text of the macro argument includes -- or ++
8794 result instanceof CrementEffect and
8895 exists ( arg .indexOf ( result .( CrementOperation ) .getOperator ( ) ) )
8996 or
97+ // If this is a functional call effect, then check that the text of the macro argument includes a call to that function
9098 result instanceof FunctionCallEffect and
9199 exists ( arg .indexOf ( result .( FunctionCall ) .getTarget ( ) .getName ( ) + "(" ) )
92100 )
0 commit comments