Skip to content

Commit 383e6a4

Browse files
committed
C++: Use or instead of if
The proposition in the true branch implied the condition, so `or` is more appropriate. Also eliminated an existentially quantified variable.
1 parent 3af9885 commit 383e6a4

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,24 @@ float widenUpperBound(Type type, float ub) {
111111
* compilation units, which doesn't necessarily have a getValue() result from the extractor.
112112
*/
113113
private string getValue(Expr e) {
114-
if exists(e.getValue())
115-
then result = e.getValue()
116-
else
117-
/*
118-
* It should be safe to propagate the initialization value to a variable if:
119-
* The type of v is const, and
120-
* The type of v is not volatile, and
121-
* Either:
122-
* v is a local/global variable, or
123-
* v is a static member variable
124-
*/
125-
126-
exists(VariableAccess access, StaticStorageDurationVariable v |
127-
not v.getUnderlyingType().isVolatile() and
128-
v.getUnderlyingType().isConst() and
129-
e = access and
130-
v = access.getTarget() and
131-
result = getValue(v.getAnAssignedValue())
132-
)
114+
result = e.getValue()
115+
or
116+
not exists(e.getValue()) and
117+
/*
118+
* It should be safe to propagate the initialization value to a variable if:
119+
* The type of v is const, and
120+
* The type of v is not volatile, and
121+
* Either:
122+
* v is a local/global variable, or
123+
* v is a static member variable
124+
*/
125+
126+
exists(StaticStorageDurationVariable v |
127+
not v.getUnderlyingType().isVolatile() and
128+
v.getUnderlyingType().isConst() and
129+
v = e.(VariableAccess).getTarget() and
130+
result = getValue(v.getAnAssignedValue())
131+
)
133132
}
134133

135134
/**

0 commit comments

Comments
 (0)