|
1 | 1 | import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis |
| 2 | +import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils // for typeLowerBound |
2 | 3 | import experimental.semmle.code.cpp.models.interfaces.SimpleRangeAnalysisExpr |
| 4 | +import experimental.semmle.code.cpp.models.interfaces.SimpleRangeAnalysisDefinition |
3 | 5 |
|
4 | 6 | class CustomAddFunctionCall extends SimpleRangeAnalysisExpr, FunctionCall { |
5 | 7 | CustomAddFunctionCall() { this.getTarget().hasGlobalName("custom_add_function") } |
@@ -37,6 +39,40 @@ class SelfSub extends SimpleRangeAnalysisExpr, SubExpr { |
37 | 39 | override predicate dependsOnChild(Expr child) { child = this.getAnOperand() } |
38 | 40 | } |
39 | 41 |
|
| 42 | +/** |
| 43 | + * A definition for test purposes of a parameter `p` that starts with a |
| 44 | + * special prefix. This class is written to exploit how QL behaves when class |
| 45 | + * fields are not functionally determined by `this`. When multiple parameters |
| 46 | + * of the same function have the special prefix, there is still only one |
| 47 | + * instance of this class. |
| 48 | + */ |
| 49 | +class MagicParameterName extends SimpleRangeAnalysisDefinition { |
| 50 | + Parameter p; |
| 51 | + float value; |
| 52 | + |
| 53 | + MagicParameterName() { |
| 54 | + this.definedByParameter(p) and |
| 55 | + value = p.getName().regexpCapture("magic_name_at_most_(\\d+)", 1).toFloat() |
| 56 | + } |
| 57 | + |
| 58 | + override predicate hasRangeInformationFor(StackVariable v) { v = p } |
| 59 | + |
| 60 | + override predicate dependsOnExpr(StackVariable v, Expr e) { |
| 61 | + // No dependencies. This sample class yields constant values. |
| 62 | + none() |
| 63 | + } |
| 64 | + |
| 65 | + override float getLowerBounds(StackVariable var) { |
| 66 | + var = p and |
| 67 | + result = typeLowerBound(p.getUnspecifiedType()) |
| 68 | + } |
| 69 | + |
| 70 | + override float getUpperBounds(StackVariable var) { |
| 71 | + var = p and |
| 72 | + result = value |
| 73 | + } |
| 74 | +} |
| 75 | + |
40 | 76 | from VariableAccess expr, float lower, float upper |
41 | 77 | where |
42 | 78 | lower = lowerBound(expr) and |
|
0 commit comments