1
+ /**
2
+ * This module implements subclasses for various DataFlow nodes that extends
3
+ * their `toString()` predicates with range information, if applicable. By
4
+ * including this module in a `path-problem` query, this range information
5
+ * will be displayed at each step in the query results.
6
+ *
7
+ * This is currently implemented for `DataFlow::ExprNode` and `DataFlow::DefinitionByReferenceNode`,
8
+ * but it is not yet implemented for `DataFlow::ParameterNode`.
9
+ */
10
+
1
11
private import cpp
2
12
private import semmle.code.cpp.dataflow.DataFlow
3
13
private import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
@@ -39,9 +49,7 @@ predicate hasIntegralOrReferenceIntegralType(Locatable e) {
39
49
// This will cover variables, parameters, type declarations, etc.
40
50
t = e .( DeclarationEntry ) .getUnspecifiedType ( )
41
51
) and
42
- isIntegralType ( t )
43
- or
44
- isIntegralReferenceType ( t )
52
+ ( isIntegralType ( t ) or isIntegralReferenceType ( t ) )
45
53
)
46
54
}
47
55
@@ -68,27 +76,24 @@ private class ExprRangeNode extends DataFlow::ExprNode {
68
76
69
77
private string getOperationBounds ( Operation e ) {
70
78
result =
71
- getExprBoundAsString ( e ) + " = " + getExprBoundAsString ( getLOp ( e ) ) +
72
- e . ( Operation ) . getOperator ( ) + getExprBoundAsString ( getROp ( e ) )
79
+ getExprBoundAsString ( e ) + " = " + getExprBoundAsString ( getLOp ( e ) ) + e . getOperator ( ) +
80
+ getExprBoundAsString ( getROp ( e ) )
73
81
}
74
82
75
83
private string getCallBounds ( Call e ) {
76
84
result =
77
85
getExprBoundAsString ( e ) + "(" +
78
- concat ( Expr arg , int i |
79
- arg = e .( Call ) .getArgument ( i )
80
- |
81
- getIntegralBounds ( arg ) order by i , ","
82
- ) + ")"
86
+ concat ( Expr arg , int i | arg = e .getArgument ( i ) | getIntegralBounds ( arg ) order by i , "," ) +
87
+ ")"
83
88
}
84
89
85
90
override string toString ( ) {
86
91
exists ( Expr e | e = getExpr ( ) |
87
92
if hasIntegralOrReferenceIntegralType ( e )
88
93
then
89
- exists ( getOperationBounds ( e ) ) and result = super .toString ( ) + ": " + getOperationBounds ( e )
94
+ result = super .toString ( ) + ": " + getOperationBounds ( e )
90
95
or
91
- exists ( getCallBounds ( e ) ) and result = super .toString ( ) + ": " + getCallBounds ( e )
96
+ result = super .toString ( ) + ": " + getCallBounds ( e )
92
97
or
93
98
not exists ( getOperationBounds ( e ) ) and
94
99
not exists ( getCallBounds ( e ) ) and
@@ -108,4 +113,3 @@ private class ReferenceArgumentRangeNode extends DataFlow::DefinitionByReference
108
113
else result = super .toString ( )
109
114
}
110
115
}
111
- // TODO: Show ranges for DataFlow::ExplicitParameterNode
0 commit comments