Skip to content

Commit 2dcec4d

Browse files
committed
CPP: Don't require alloc in memberMayBeVarSize.
1 parent 035823c commit 2dcec4d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

cpp/ql/src/semmle/code/cpp/commons/Buffer.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ predicate memberMayBeVarSize(Class c, MemberVariable v) {
3434
// `sizeof(c)` is taken
3535
so.(SizeofTypeOperator).getTypeOperand().getUnspecifiedType() = c or
3636
so.(SizeofExprOperator).getExprOperand().getType().getUnspecifiedType() = c |
37-
// Check all ancestor nodes except the immediate parent for
38-
// allocations.
39-
isStdLibAllocationExpr(so.getParent().(Expr).getParent+())
37+
38+
// arithmetic is performed on the result
39+
so.getParent*() instanceof BinaryArithmeticOperation
4040
) or exists(AddressOfExpr aoe |
4141
// `&(c.v)` is taken
42-
aoe.getAddressable() = v and
43-
isStdLibAllocationExpr(aoe.getParent().(Expr).getParent+())
42+
aoe.getAddressable() = v
4443
)
4544
)
4645
}

0 commit comments

Comments
 (0)