mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C++: respond to overflow PR comments
This commit is contained in:
@@ -21,7 +21,7 @@ module FloatDelta implements DeltaSig {
|
||||
}
|
||||
|
||||
module FloatOverflow implements OverflowSig<FloatDelta> {
|
||||
predicate semExprDoesntOverflow(boolean positively, SemExpr expr) {
|
||||
predicate semExprDoesNotOverflow(boolean positively, SemExpr expr) {
|
||||
exists(float lb, float ub, float delta |
|
||||
typeBounds(expr.getSemType(), lb, ub) and
|
||||
ConstantStage::initialBounded(expr, any(ConstantBounds::SemZeroBound b), delta, positively, _, _, _)
|
||||
@@ -31,17 +31,8 @@ module FloatOverflow implements OverflowSig<FloatDelta> {
|
||||
positively = false and delta > lb
|
||||
)
|
||||
}
|
||||
/*
|
||||
predicate semExprOverflow(float delta, boolean upper, SemExpr expr) {
|
||||
exists(float lb, float ub | typeBounds(expr.getSemType(), lb, ub) |
|
||||
upper = false and delta < lb
|
||||
or
|
||||
upper = true and delta > ub
|
||||
)
|
||||
}
|
||||
*/
|
||||
|
||||
predicate typeBounds(SemType t, float lb, float ub) {
|
||||
additional predicate typeBounds(SemType t, float lb, float ub) {
|
||||
exists(SemIntegerType integralType, float limit |
|
||||
integralType = t and limit = 2.pow(8 * integralType.getByteSize())
|
||||
|
|
||||
|
||||
@@ -6,7 +6,7 @@ private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
|
||||
private import RangeAnalysisStage
|
||||
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
|
||||
|
||||
module CppLangImpl implements LangSig<FloatDelta> {
|
||||
module CppLangImplConstant implements LangSig<FloatDelta> {
|
||||
/**
|
||||
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
|
||||
*
|
||||
@@ -1,5 +1,6 @@
|
||||
private import RangeAnalysisStage
|
||||
private import RangeAnalysisSpecific
|
||||
private import RangeAnalysisConstantSpecific
|
||||
private import RangeAnalysisRelativeSpecific
|
||||
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
|
||||
private import RangeUtils
|
||||
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticBound as SemanticBound
|
||||
@@ -47,10 +48,10 @@ module RelativeBounds implements BoundSig<FloatDelta> {
|
||||
}
|
||||
|
||||
module ConstantStage =
|
||||
RangeStage<FloatDelta, ConstantBounds, FloatOverflow, CppLangImpl, RangeUtil<FloatDelta, CppLangImpl>>;
|
||||
RangeStage<FloatDelta, ConstantBounds, FloatOverflow, CppLangImplConstant, RangeUtil<FloatDelta, CppLangImplConstant>>;
|
||||
|
||||
module RelativeStage =
|
||||
RangeStage<FloatDelta, RelativeBounds, FloatOverflow, CppLangImpl, RangeUtil<FloatDelta, CppLangImpl>>;
|
||||
RangeStage<FloatDelta, RelativeBounds, FloatOverflow, CppLangImplRelative, RangeUtil<FloatDelta, CppLangImplRelative>>;
|
||||
|
||||
private newtype TSemReason =
|
||||
TSemNoReason() or
|
||||
|
||||
@@ -9,7 +9,7 @@ private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.IntD
|
||||
private import RangeAnalysisImpl
|
||||
private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
|
||||
|
||||
module CppLangImpl2 implements LangSig<FloatDelta> {
|
||||
module CppLangImplRelative implements LangSig<FloatDelta> {
|
||||
/**
|
||||
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
|
||||
*
|
||||
@@ -242,7 +242,7 @@ signature module BoundSig<DeltaSig D> {
|
||||
}
|
||||
|
||||
signature module OverflowSig<DeltaSig D> {
|
||||
predicate semExprDoesntOverflow(boolean positively, SemExpr expr);
|
||||
predicate semExprDoesNotOverflow(boolean positively, SemExpr expr);
|
||||
}
|
||||
|
||||
module RangeStage<
|
||||
@@ -935,12 +935,10 @@ module RangeStage<
|
||||
) {
|
||||
initialBounded(e, b, delta, upper, fromBackEdge, origdelta, reason) and
|
||||
(
|
||||
semExprDoesntOverflow(upper.booleanNot(), e)
|
||||
semExprDoesNotOverflow(upper.booleanNot(), e)
|
||||
or
|
||||
not potentiallyOverflowingExpr(upper.booleanNot(), e)
|
||||
or
|
||||
initialBounded(e, any(SemZeroBound z), _, upper.booleanNot(), _, _, _)
|
||||
or
|
||||
exists(D::Delta otherDelta |
|
||||
initialBounded(e, _, otherDelta, upper.booleanNot(), _, _, _) and
|
||||
(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
|
||||
private import RangeAnalysisSpecific
|
||||
private import RangeAnalysisRelativeSpecific
|
||||
private import RangeAnalysisStage as Range
|
||||
private import ConstantAnalysis
|
||||
|
||||
|
||||
Reference in New Issue
Block a user