Skip to content

Commit fa123a7

Browse files
authored
Merge pull request github#18200 from github/calumgrant/bmn/wrong-type-format-args2
C++: Fix more FPs with extraction errors on cpp/wrong-type-format-arguments
2 parents a555a44 + 5aa604b commit fa123a7

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
) and
171171
not arg.isAffectedByMacro() and
172172
not arg.isFromUninstantiatedTemplate(_) and
173-
not actual.getUnspecifiedType() instanceof ErroneousType and
173+
not actual.stripType() instanceof ErroneousType and
174174
not arg.(Call).mayBeFromImplicitlyDeclaredFunction()
175175
select arg,
176176
"This format specifier for type '" + expected.getName() + "' does not match the argument type '" +
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Wrong type of arguments to formatting function" query (`cpp/wrong-type-format-argument`) no longer produces results when an argument type has an extraction error.

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
int printf(const char * format, ...);
44
int fprintf();
55

6-
void f() {
6+
void f(UNKNOWN_CHAR * str) {
77
printf("%s", 1); // BAD
88
printf("%s", implicit_function()); // GOOD - we should ignore the type
99
sprintf(0, "%s", ""); // GOOD
1010
fprintf(0, "%s", ""); // GOOD
11+
printf("%s", str); // GOOD - erroneous type is ignored
1112
}

0 commit comments

Comments
 (0)