Skip to content

Commit a083569

Browse files
authored
Merge pull request github#14382 from MathiasVP/deduplicate-why
C++: Project away `why` to prevent tuple duplication in `Buffer.qll`
2 parents 7436854 + 2f39ab1 commit a083569

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ private int isSource(Expr bufferExpr, Element why) {
7373
)
7474
}
7575

76+
/** Same as `getBufferSize`, but with the `why` column projected away to prevent large duplications. */
77+
pragma[nomagic]
78+
int getBufferSizeProj(Expr bufferExpr) { result = getBufferSize(bufferExpr, _) }
79+
7680
/**
7781
* Get the size in bytes of the buffer pointed to by an expression (if this can be determined).
7882
*/
@@ -87,15 +91,14 @@ int getBufferSize(Expr bufferExpr, Element why) {
8791
why = bufferVar and
8892
parentPtr = bufferExpr.(VariableAccess).getQualifier() and
8993
parentPtr.getTarget().getUnspecifiedType().(PointerType).getBaseType() = parentClass and
90-
result = getBufferSize(parentPtr, _) + bufferSize - parentClass.getSize()
94+
result = getBufferSizeProj(parentPtr) + bufferSize - parentClass.getSize()
9195
|
9296
if exists(bufferVar.getType().getSize())
9397
then bufferSize = bufferVar.getType().getSize()
9498
else bufferSize = 0
9599
)
96100
or
97101
// dataflow (all sources must be the same size)
98-
result = unique(Expr def | DataFlow::localExprFlowStep(def, bufferExpr) | getBufferSize(def, _)) and
99-
// find reason
102+
result = unique(Expr def | DataFlow::localExprFlowStep(def, bufferExpr) | getBufferSizeProj(def)) and
100103
exists(Expr def | DataFlow::localExprFlowStep(def, bufferExpr) | exists(getBufferSize(def, why)))
101104
}

0 commit comments

Comments
 (0)