mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Java: Use range analysis in IntMultToLong.
This commit is contained in:
@@ -18,15 +18,26 @@
|
||||
|
||||
import java
|
||||
import semmle.code.java.dataflow.RangeUtils
|
||||
import semmle.code.java.dataflow.RangeAnalysis
|
||||
import semmle.code.java.Conversions
|
||||
|
||||
/** An multiplication that does not overflow. */
|
||||
/** Gets an upper bound on the absolute value of `e`. */
|
||||
float exprBound(Expr e) {
|
||||
result = e.(ConstantIntegerExpr).getIntValue().(float).abs()
|
||||
or
|
||||
exists(float lower, float upper |
|
||||
bounded(e, any(ZeroBound zb), lower, false, _) and
|
||||
bounded(e, any(ZeroBound zb), upper, true, _) and
|
||||
result = upper.abs().maximum(lower.abs())
|
||||
)
|
||||
}
|
||||
|
||||
/** A multiplication that does not overflow. */
|
||||
predicate small(MulExpr e) {
|
||||
exists(NumType t, float lhs, float rhs, float res | t = e.getType() |
|
||||
lhs = e.getLeftOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
|
||||
rhs = e.getRightOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
|
||||
lhs = exprBound(e.getLeftOperand().getProperExpr()) and
|
||||
rhs = exprBound(e.getRightOperand().getProperExpr()) and
|
||||
lhs * rhs = res and
|
||||
t.getOrdPrimitiveType().getMinValue() <= res and
|
||||
res <= t.getOrdPrimitiveType().getMaxValue()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user