Skip to content

Commit db08076

Browse files
committed
C++: Fixed false negative
1 parent 229da0a commit db08076

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class SubAnalyzableExpr extends AnalyzableExpr, SubExpr {
132132
}
133133

134134
class VarAnalyzableExpr extends AnalyzableExpr, VariableAccess {
135+
VarAnalyzableExpr() { not exists(this.getQualifier()) }
136+
135137
override float maxValue() {
136138
exists(SsaDefinition def, Variable v |
137139
def.getAUse(v) = this and
@@ -140,7 +142,7 @@ class VarAnalyzableExpr extends AnalyzableExpr, VariableAccess {
140142
// variable the largest possible value it can hold
141143
if exists(def.getDefiningValue(v))
142144
then result = def.getDefiningValue(v).(AnalyzableExpr).maxValue()
143-
else result = exprMaxVal(this)
145+
else result = upperBound(this)
144146
)
145147
}
146148

@@ -149,7 +151,7 @@ class VarAnalyzableExpr extends AnalyzableExpr, VariableAccess {
149151
def.getAUse(v) = this and
150152
if exists(def.getDefiningValue(v))
151153
then result = def.getDefiningValue(v).(AnalyzableExpr).minValue()
152-
else result = exprMinVal(this)
154+
else result = lowerBound(this)
153155
)
154156
}
155157
}
@@ -206,9 +208,9 @@ where
206208
) and
207209
e.(Literal).getType().getSize() = t2.getSize()
208210
) and
209-
// only report if cannot prove that the result of the
211+
// only report if we cannot prove that the result of the
210212
// multiplication will be less (resp. greater) than the
211-
// maximum (resp. minimum) number we can store.
213+
// maximum (resp. minimum) number we can compute.
212214
overflows(me, t1)
213215
select me,
214216
"Multiplication result may overflow '" + me.getType().toString() + "' before it is converted to '"

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/IntMultToLong/IntMultToLong.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
| IntMultToLong.c:99:14:99:35 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
1111
| IntMultToLong.c:103:14:103:46 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
1212
| IntMultToLong.c:108:14:108:78 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
13+
| IntMultToLong.c:119:14:119:26 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |

0 commit comments

Comments
 (0)