Skip to content

Commit a33b7f8

Browse files
committed
Make getSizeMult() functional.
1 parent 293e646 commit a33b7f8

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Allocation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private predicate deconstructSizeExpr(Expr sizeExpr, Expr lengthExpr, int sizeof
261261
exists(SizeofOperator sizeofOp |
262262
sizeofOp = sizeExpr.(MulExpr).getAnOperand() and
263263
lengthExpr = sizeExpr.(MulExpr).getAnOperand() and
264-
sizeofOp != lengthExpr and
264+
not lengthExpr instanceof SizeofOperator and
265265
sizeof = sizeofOp.getValue().toInt()
266266
)
267267
or

cpp/ql/test/library-tests/allocators/allocators.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,5 @@ void testMalloc(size_t count) {
159159
malloc(count * sizeof(int));
160160
malloc(count * sizeof(int) + 1);
161161
malloc(((int) count) * sizeof(void *));
162+
malloc(sizeof(void*) * sizeof(int));
162163
}

cpp/ql/test/library-tests/allocators/allocators.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ allocationExprs
9191
| allocators.cpp:159:3:159:8 | call to malloc | getSizeExpr = count, getSizeMult = 4, requiresDealloc |
9292
| allocators.cpp:160:3:160:8 | call to malloc | getSizeExpr = ... + ..., getSizeMult = 1, requiresDealloc |
9393
| allocators.cpp:161:3:161:8 | call to malloc | getSizeExpr = count, getSizeMult = 8, requiresDealloc |
94+
| allocators.cpp:162:3:162:8 | call to malloc | getSizeExpr = ... * ..., requiresDealloc |
9495
deallocationFunctions
9596
| allocators.cpp:11:6:11:20 | operator delete | getFreedArg = 0 |
9697
| allocators.cpp:12:6:12:22 | operator delete[] | getFreedArg = 0 |

0 commit comments

Comments
 (0)