Skip to content

Commit 247fc42

Browse files
committed
Add tests that show AllocationExpr.getSizeMult() behaviour.
1 parent 471f536 commit 247fc42

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,14 @@ void directOperatorCall() {
149149
ptr = operator new(sizeof(int));
150150
operator delete(ptr);
151151
}
152+
153+
void *malloc(size_t);
154+
155+
void testMalloc(size_t count) {
156+
malloc(5);
157+
malloc(5 * sizeof(int));
158+
malloc(count);
159+
malloc(count * sizeof(int));
160+
malloc(count * sizeof(int) + 1);
161+
malloc(((int) count) * sizeof(void *));
162+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ allocationFunctions
5555
| allocators.cpp:122:7:122:20 | operator new[] | getPlacementArgument = 1, getSizeArg = 0 |
5656
| allocators.cpp:123:7:123:18 | operator new | getSizeArg = 0, requiresDealloc |
5757
| allocators.cpp:124:7:124:20 | operator new[] | getSizeArg = 0, requiresDealloc |
58+
| allocators.cpp:153:7:153:12 | malloc | getSizeArg = 0, requiresDealloc |
5859
| file://:0:0:0:0 | operator new | getSizeArg = 0, requiresDealloc |
5960
| file://:0:0:0:0 | operator new | getSizeArg = 0, requiresDealloc |
6061
| file://:0:0:0:0 | operator new[] | getSizeArg = 0, requiresDealloc |
@@ -84,6 +85,12 @@ allocationExprs
8485
| allocators.cpp:143:13:143:28 | new[] | getSizeBytes = 400, requiresDealloc |
8586
| allocators.cpp:144:13:144:31 | new[] | getSizeExpr = x, getSizeMult = 900, requiresDealloc |
8687
| allocators.cpp:149:8:149:19 | call to operator new | getSizeBytes = 4, getSizeExpr = sizeof(int), getSizeMult = 1, requiresDealloc |
88+
| allocators.cpp:156:3:156:8 | call to malloc | getSizeBytes = 5, getSizeExpr = 5, getSizeMult = 1, requiresDealloc |
89+
| allocators.cpp:157:3:157:8 | call to malloc | getSizeBytes = 20, getSizeExpr = ... * ..., getSizeMult = 1, requiresDealloc |
90+
| allocators.cpp:158:3:158:8 | call to malloc | getSizeExpr = count, getSizeMult = 1, requiresDealloc |
91+
| allocators.cpp:159:3:159:8 | call to malloc | getSizeExpr = ... * ..., getSizeMult = 1, requiresDealloc |
92+
| allocators.cpp:160:3:160:8 | call to malloc | getSizeExpr = ... + ..., getSizeMult = 1, requiresDealloc |
93+
| allocators.cpp:161:3:161:8 | call to malloc | getSizeExpr = ... * ..., getSizeMult = 1, requiresDealloc |
8794
deallocationFunctions
8895
| allocators.cpp:11:6:11:20 | operator delete | getFreedArg = 0 |
8996
| allocators.cpp:12:6:12:22 | operator delete[] | getFreedArg = 0 |

0 commit comments

Comments
 (0)