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+
111private import cpp
212private import semmle.code.cpp.dataflow.DataFlow
313private import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
@@ -39,9 +49,7 @@ predicate hasIntegralOrReferenceIntegralType(Locatable e) {
3949 // This will cover variables, parameters, type declarations, etc.
4050 t = e .( DeclarationEntry ) .getUnspecifiedType ( )
4151 ) and
42- isIntegralType ( t )
43- or
44- isIntegralReferenceType ( t )
52+ ( isIntegralType ( t ) or isIntegralReferenceType ( t ) )
4553 )
4654}
4755
@@ -68,27 +76,24 @@ private class ExprRangeNode extends DataFlow::ExprNode {
6876
6977 private string getOperationBounds ( Operation e ) {
7078 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 ) )
7381 }
7482
7583 private string getCallBounds ( Call e ) {
7684 result =
7785 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+ ")"
8388 }
8489
8590 override string toString ( ) {
8691 exists ( Expr e | e = getExpr ( ) |
8792 if hasIntegralOrReferenceIntegralType ( e )
8893 then
89- exists ( getOperationBounds ( e ) ) and result = super .toString ( ) + ": " + getOperationBounds ( e )
94+ result = super .toString ( ) + ": " + getOperationBounds ( e )
9095 or
91- exists ( getCallBounds ( e ) ) and result = super .toString ( ) + ": " + getCallBounds ( e )
96+ result = super .toString ( ) + ": " + getCallBounds ( e )
9297 or
9398 not exists ( getOperationBounds ( e ) ) and
9499 not exists ( getCallBounds ( e ) ) and
@@ -108,4 +113,3 @@ private class ReferenceArgumentRangeNode extends DataFlow::DefinitionByReference
108113 else result = super .toString ( )
109114 }
110115}
111- // TODO: Show ranges for DataFlow::ExplicitParameterNode
0 commit comments