зеркало из https://github.com/github/codeql.git
C++: Handle constant variable accesses in SimpleRangeAnalysis.qll
This commit is contained in:
Родитель
bbcf0b52df
Коммит
6dee7061a0
|
@ -91,13 +91,30 @@ private float wideningUpperBounds(ArithmeticType t) {
|
||||||
result = 1.0 / 0.0 // +Inf
|
result = 1.0 / 0.0 // +Inf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the expression `e`, if it is a constant.
|
||||||
|
* This predicate also handles the case of constant variables initialized in compilation units,
|
||||||
|
* which doesn't necessarily have a getValue() result from the extractor.
|
||||||
|
*/
|
||||||
|
private string getValue(Expr e) {
|
||||||
|
if exists(e.getValue())
|
||||||
|
then result = e.getValue()
|
||||||
|
else
|
||||||
|
exists(VariableAccess access, Variable v |
|
||||||
|
e = access and
|
||||||
|
v = access.getTarget() and
|
||||||
|
v.getType().isConst() and
|
||||||
|
result = getValue(v.getAnAssignedValue())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/** Set of expressions which we know how to analyze. */
|
/** Set of expressions which we know how to analyze. */
|
||||||
private predicate analyzableExpr(Expr e) {
|
private predicate analyzableExpr(Expr e) {
|
||||||
// The type of the expression must be arithmetic. We reuse the logic in
|
// The type of the expression must be arithmetic. We reuse the logic in
|
||||||
// `exprMinVal` to check this.
|
// `exprMinVal` to check this.
|
||||||
exists(exprMinVal(e)) and
|
exists(exprMinVal(e)) and
|
||||||
(
|
(
|
||||||
exists(e.getValue().toFloat()) or
|
exists(getValue(e).toFloat()) or
|
||||||
e instanceof UnaryPlusExpr or
|
e instanceof UnaryPlusExpr or
|
||||||
e instanceof UnaryMinusExpr or
|
e instanceof UnaryMinusExpr or
|
||||||
e instanceof MinExpr or
|
e instanceof MinExpr or
|
||||||
|
|
Загрузка…
Ссылка в новой задаче