Skip to content

Commit 100ace5

Browse files
committed
C++: Fixed handling of false negative. Query now supports global variables
1 parent db08076 commit 100ace5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SubAnalyzableExpr extends AnalyzableExpr, SubExpr {
132132
}
133133

134134
class VarAnalyzableExpr extends AnalyzableExpr, VariableAccess {
135-
VarAnalyzableExpr() { not exists(this.getQualifier()) }
135+
VarAnalyzableExpr() { this.getTarget() instanceof StackVariable }
136136

137137
override float maxValue() {
138138
exists(SsaDefinition def, Variable v |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,12 @@ void g2(struct A* a, short n) {
117117
unsigned long ulong1, ulong2;
118118
ulong1 = (a->s - 1) * ((*a).s + 1); // GOOD
119119
ulong2 = a->i * (*a).i; // BAD
120+
}
121+
122+
int global_i;
123+
unsigned char global_uchar;
124+
void g3() {
125+
unsigned long ulong1, ulong2;
126+
ulong1 = global_i * global_i; // BAD
127+
ulong2 = (global_uchar + 1) * 2; // GOOD
120128
}

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
@@ -11,3 +11,4 @@
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'. |
1313
| IntMultToLong.c:119:14:119:26 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |
14+
| IntMultToLong.c:126:14:126:32 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'unsigned long'. |

0 commit comments

Comments
 (0)