Skip to content

Commit 7d7498e

Browse files
committed
C++: Avoid problems when a variable has multiple types.
1 parent 812315d commit 7d7498e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ private int isSource(Expr bufferExpr, Element why) {
106106
exists(Variable bufferVar | bufferVar = bufferExpr.(VariableAccess).getTarget() |
107107
// buffer is a fixed size array
108108
exists(bufferVar.getUnspecifiedType().(ArrayType).getSize()) and
109-
result = getSize(bufferExpr) and // more generous than .getSize() itself, when the array is a class field or similar.
109+
result =
110+
unique(int size | // more generous than .getSize() itself, when the array is a class field or similar.
111+
size = getSize(bufferExpr)
112+
|
113+
size
114+
) and
110115
why = bufferVar and
111116
not memberMayBeVarSize(_, bufferVar) and
112117
not exists(BuiltInOperationBuiltInOffsetOf offsetof | offsetof.getAChild*() = bufferExpr) and

0 commit comments

Comments
 (0)