Skip to content

Commit 78642aa

Browse files
authored
Merge pull request #7593 from MathiasVP/fix-join-order-in-get-conversion-type
C++: Fix join order in 'getConversionType4'
2 parents 6a53b7b + 6d95d47 commit 78642aa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ private int lengthInBase10(float f) {
382382
result = f.log10().floor() + 1
383383
}
384384

385+
pragma[nomagic]
386+
private predicate isPointerTypeWithBase(Type base, PointerType pt) { base = pt.getBaseType() }
387+
385388
bindingset[expr]
386389
private BufferWriteEstimationReason getEstimationReasonForIntegralExpression(Expr expr) {
387390
// we consider the range analysis non trivial if it
@@ -962,19 +965,19 @@ class FormatLiteral extends Literal {
962965
(
963966
conv = ["s", "S"] and
964967
len = "h" and
965-
result.(PointerType).getBaseType() instanceof PlainCharType
968+
isPointerTypeWithBase(any(PlainCharType plainCharType), result)
966969
or
967970
conv = ["s", "S"] and
968971
len = ["l", "w"] and
969-
result.(PointerType).getBaseType() = this.getWideCharType()
972+
isPointerTypeWithBase(this.getWideCharType(), result)
970973
or
971974
conv = "s" and
972975
(len != "l" and len != "w" and len != "h") and
973-
result.(PointerType).getBaseType() = this.getDefaultCharType()
976+
isPointerTypeWithBase(this.getDefaultCharType(), result)
974977
or
975978
conv = "S" and
976979
(len != "l" and len != "w" and len != "h") and
977-
result.(PointerType).getBaseType() = this.getNonDefaultCharType()
980+
isPointerTypeWithBase(this.getNonDefaultCharType(), result)
978981
)
979982
)
980983
}

0 commit comments

Comments
 (0)