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

Skip to content

Commit 9d2533c

Browse files
committed
Fix bug in handling of subtractions.
1 parent e6d1932 commit 9d2533c

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

cpp/ql/src/experimental/library/ArrayLengthAnalysis.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ private predicate deconstructMallocSizeExpr(Expr sizeExpr, Expr lengthExpr, int
176176
or
177177
sizeExpr instanceof SubExpr and
178178
exists(Expr constantExpr |
179-
lengthExpr = sizeExpr.(SubExpr).getAnOperand() and
180-
constantExpr = sizeExpr.(SubExpr).getAnOperand() and
181-
lengthExpr != constantExpr and
179+
lengthExpr = sizeExpr.(SubExpr).getLeftOperand() and
180+
constantExpr = sizeExpr.(SubExpr).getRightOperand() and
182181
delta = -constantExpr.getValue().toInt()
183182
)
184183
}

cpp/ql/test/experimental/library-tests/arraylengthanalysis/ArrayLengthAnalysisTest.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
| test.cpp:80:8:80:8 | Load: a | VNLength(InitializeParameter: count) | 1 | OpOffset(Load: count) | 1 |
2323
| test.cpp:85:8:85:8 | Load: a | VNLength(InitializeParameter: count) | 1 | OpOffset(Add: ... + ...) | 0 |
2424
| test.cpp:87:8:87:8 | Load: a | VNLength(InitializeParameter: count) | 1 | OpOffset(Add: ... + ...) | 1 |
25+
| test.cpp:89:8:89:8 | Load: a | VNLength(Sub: ... - ...) | 0 | ZeroOffset | 0 |

cpp/ql/test/experimental/library-tests/arraylengthanalysis/test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ void test2(unsigned int count, bool b) {
8585
sink(a); // TODO, should be (count, 1, count, 1), but is (count, 1, count + 1, 0)
8686
a += 1;
8787
sink(a); // TODO, should be (count, 1, count, 2), but is (count, 1, count + 1, 1)
88+
a = (int*) malloc(sizeof(int) * (1024 - count));
89+
sink(a); // (1024-count, 0, Zero, 0)
8890
}

0 commit comments

Comments
 (0)