Skip to content

Commit

Permalink
Merge pull request #18200 from github/calumgrant/bmn/wrong-type-forma…
Browse files Browse the repository at this point in the history
…t-args2

C++: Fix more FPs with extraction errors on cpp/wrong-type-format-arguments
  • Loading branch information
calumgrant authored Dec 6, 2024
2 parents a555a44 + 5aa604b commit fa123a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
) and
not arg.isAffectedByMacro() and
not arg.isFromUninstantiatedTemplate(_) and
not actual.getUnspecifiedType() instanceof ErroneousType and
not actual.stripType() instanceof ErroneousType and
not arg.(Call).mayBeFromImplicitlyDeclaredFunction()
select arg,
"This format specifier for type '" + expected.getName() + "' does not match the argument type '" +
Expand Down
4 changes: 4 additions & 0 deletions cpp/ql/src/change-notes/2024-12-05-wrong-type-format-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
int printf(const char * format, ...);
int fprintf();

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

0 comments on commit fa123a7

Please sign in to comment.