Skip to content

Commit b2b4523

Browse files
committed
C++: use rounding to prevent float wobble in range analysis
1 parent 31b61b1 commit b2b4523

File tree

4 files changed

+137
-113
lines changed

4 files changed

+137
-113
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/FloatDelta.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ module FloatDelta implements DeltaSig {
1616
Delta fromInt(int n) { result = n }
1717

1818
bindingset[f]
19-
bindingset[result]
20-
Delta fromFloat(float f) { result = f }
19+
Delta fromFloat(float f) { result = min(float diff, float res | diff = (res - f).abs() and res = f.ceil() or diff = (f - res).abs() and res = f.floor() | res order by diff )}
2120
}

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysisSpecific.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
private import experimental.semmle.code.cpp.semantic.Semantic
66
private import RangeAnalysisStage
77
private import experimental.semmle.code.cpp.semantic.analysis.FloatDelta
8+
private import experimental.semmle.code.cpp.semantic.analysis.IntDelta
89

910
module CppLangImpl implements LangSig<FloatDelta> {
1011
/**

0 commit comments

Comments
 (0)