Skip to content

Commit 5bf7e45

Browse files
committed
C++: Tidy up WrongTypeFormatArguments.ql somewhat.
1 parent 6e49891 commit 5bf7e45

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ private predicate formattingFunctionCallAlternateType(
5252

5353
/**
5454
* Holds if the argument corresponding to the `pos` conversion specifier
55-
* of `ffc` is expected to have type `expected` and the corresponding
56-
* argument `arg` has type `actual`.
55+
* of `ffc` is `arg` and has type `actual`.
5756
*/
5857
pragma[noopt]
59-
predicate formatArgType(FormattingFunctionCall ffc, int pos, Type expected, Expr arg, Type actual) {
58+
predicate formattingFunctionCallActualType(
59+
FormattingFunctionCall ffc, int pos, Expr arg, Type actual
60+
) {
6061
exists(Expr argConverted |
61-
formattingFunctionCallExpectedType(ffc, pos, expected) and
6262
ffc.getConversionArgument(pos) = arg and
6363
argConverted = arg.getFullyConverted() and
6464
actual = argConverted.getType()
@@ -90,7 +90,7 @@ class ExpectedType extends Type {
9090
ExpectedType() {
9191
exists(Type t |
9292
(
93-
formatArgType(_, _, t, _, _) or
93+
formattingFunctionCallExpectedType(_, _, t) or
9494
formattingFunctionCallAlternateType(_, _, t) or
9595
formatOtherArgType(_, _, t, _, _)
9696
) and
@@ -111,10 +111,10 @@ class ExpectedType extends Type {
111111
predicate trivialConversion(ExpectedType expected, Type actual) {
112112
exists(Type exp, Type act |
113113
(
114-
formatArgType(_, _, exp, _, _) or
114+
formattingFunctionCallExpectedType(_, _, exp) or
115115
formattingFunctionCallAlternateType(_, _, exp)
116116
) and
117-
formatArgType(_, _, _, _, act) and
117+
formattingFunctionCallActualType(_, _, _, act) and
118118
expected = exp.getUnspecifiedType() and
119119
actual = act.getUnspecifiedType()
120120
) and
@@ -169,10 +169,11 @@ int sizeof_IntType() { exists(IntType it | result = it.getSize()) }
169169
from FormattingFunctionCall ffc, int n, Expr arg, Type expected, Type actual
170170
where
171171
(
172-
formatArgType(ffc, n, expected, arg, actual) and
172+
formattingFunctionCallExpectedType(ffc, n, expected) and
173+
formattingFunctionCallActualType(ffc, n, arg, actual) and
173174
not exists(Type anyExpected |
174175
(
175-
formatArgType(ffc, n, anyExpected, arg, actual) or
176+
formattingFunctionCallExpectedType(ffc, n, anyExpected) or
176177
formattingFunctionCallAlternateType(ffc, n, anyExpected)
177178
) and
178179
trivialConversion(anyExpected.getUnspecifiedType(), actual.getUnspecifiedType())

0 commit comments

Comments
 (0)