Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 525a000

Browse files
committed
C++: Address review comments
1 parent 6dee706 commit 525a000

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,23 @@ private float wideningUpperBounds(ArithmeticType t) {
9696
* This predicate also handles the case of constant variables initialized in compilation units,
9797
* which doesn't necessarily have a getValue() result from the extractor.
9898
*/
99-
private string getValue(Expr e) {
99+
private string getValue0(Expr e) {
100100
if exists(e.getValue())
101101
then result = e.getValue()
102102
else
103103
exists(VariableAccess access, Variable v |
104104
e = access and
105105
v = access.getTarget() and
106-
v.getType().isConst() and
107-
result = getValue(v.getAnAssignedValue())
106+
v.getUnderlyingType().isConst() and
107+
result = getValue0(v.getAnAssignedValue())
108108
)
109109
}
110110

111+
private string getValue(Expr e) {
112+
result = min(getValue0(e)) and
113+
result = max(getValue0(e))
114+
}
115+
111116
/** Set of expressions which we know how to analyze. */
112117
private predicate analyzableExpr(Expr e) {
113118
// The type of the expression must be arithmetic. We reuse the logic in
@@ -382,8 +387,8 @@ private float getTruncatedLowerBounds(Expr expr) {
382387
then
383388
// If the expression evaluates to a constant, then there is no
384389
// need to call getLowerBoundsImpl.
385-
if exists(expr.getValue().toFloat())
386-
then result = expr.getValue().toFloat()
390+
if exists(getValue(expr).toFloat())
391+
then result = getValue(expr).toFloat()
387392
else (
388393
// Some of the bounds computed by getLowerBoundsImpl might
389394
// overflow, so we replace invalid bounds with exprMinVal.
@@ -435,8 +440,8 @@ private float getTruncatedUpperBounds(Expr expr) {
435440
then
436441
// If the expression evaluates to a constant, then there is no
437442
// need to call getUpperBoundsImpl.
438-
if exists(expr.getValue().toFloat())
439-
then result = expr.getValue().toFloat()
443+
if exists(getValue(expr).toFloat())
444+
then result = getValue(expr).toFloat()
440445
else (
441446
// Some of the bounds computed by `getUpperBoundsImpl`
442447
// might overflow, so we replace invalid bounds with

0 commit comments

Comments
 (0)