Skip to content

Commit 4907677

Browse files
committed
C++: Try to improve QLDoc on deconstructSizeExpr.
1 parent 33f4503 commit 4907677

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,15 @@ class OperatorNewAllocationFunction extends AllocationFunction {
271271
}
272272

273273
/**
274-
* The predicate analyzes a `sizeExpr`, which is an argument to an allocation
275-
* function like malloc, and tries to split it into an expression `lengthExpr`
276-
* that describes the length of the allocated array, and the size of the allocated
277-
* element type `sizeof`.
278-
* If this is not possible, the allocation is considered to be of size 1 and of
279-
* length `sizeExpr`.
274+
* Holds if `sizeExpr` is an expression consisting of a subexpression
275+
* `lengthExpr` multiplied by a constant `sizeof` that is the result of a
276+
* `sizeof()` expression. Alternatively if there isn't a suitable `sizeof()`
277+
* expression, `lengthExpr = sizeExpr` and `sizeof = 1`. For example:
278+
* ```
279+
* malloc(a * 2 * sizeof(char32_t));
280+
* ```
281+
* In this case if the `sizeExpr` is the argument to `malloc`, the `lengthExpr`
282+
* is `a * 2` and `sizeof` is `4`.
280283
*/
281284
private predicate deconstructSizeExpr(Expr sizeExpr, Expr lengthExpr, int sizeof) {
282285
if

0 commit comments

Comments
 (0)