Skip to content

Commit 3f7d681

Browse files
committed
Use stripTopLevelSpecifiers() to get the allocated element type for malloc().
1 parent 92e8604 commit 3f7d681

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ class CallAllocationExpr extends AllocationExpr, FunctionCall {
343343
override Expr getReallocPtr() { result = getArgument(target.getReallocPtrArg()) }
344344

345345
override Type getAllocatedElementType() {
346-
result = this.getFullyConverted().getUnderlyingType().(PointerType).getBaseType() and
346+
result =
347+
this.getFullyConverted().getType().stripTopLevelSpecifiers().(PointerType).getBaseType() and
347348
not result instanceof VoidType
348349
}
349350

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ allocationExprs
8686
| allocators.cpp:144:13:144:31 | new[] | getAllocatedElementType = char[30][30], getSizeExpr = x, getSizeMult = 900, requiresDealloc |
8787
| allocators.cpp:149:8:149:19 | call to operator new | getSizeBytes = 4, getSizeExpr = sizeof(int), getSizeMult = 1, requiresDealloc |
8888
| allocators.cpp:157:50:157:55 | call to malloc | getAllocatedElementType = const volatile int, getSizeBytes = 5, getSizeExpr = 5, getSizeMult = 1, requiresDealloc |
89-
| allocators.cpp:158:26:158:31 | call to malloc | getSizeBytes = 20, getSizeExpr = 5, getSizeMult = 4, requiresDealloc |
89+
| allocators.cpp:158:26:158:31 | call to malloc | getAllocatedElementType = int, getSizeBytes = 20, getSizeExpr = 5, getSizeMult = 4, requiresDealloc |
9090
| allocators.cpp:159:31:159:36 | call to malloc | getAllocatedElementType = volatile long, getSizeExpr = count, getSizeMult = 1, requiresDealloc |
9191
| allocators.cpp:160:16:160:21 | call to malloc | getAllocatedElementType = volatile long, getSizeExpr = count, getSizeMult = 4, requiresDealloc |
9292
| allocators.cpp:161:34:161:39 | call to malloc | getAllocatedElementType = const char, getSizeExpr = ... + ..., getSizeMult = 1, requiresDealloc |

0 commit comments

Comments
 (0)