Skip to content

Commit 406cc64

Browse files
authored
Merge pull request #4831 from geoffw0/printfunknown
C++: Fix Printf.qll specsAreKnown
2 parents 9ae8880 + 93dfeac commit 406cc64

File tree

2 files changed

+5
-0
lines changed
  • cpp/ql
    • src/semmle/code/cpp/commons
    • test/query-tests/Likely Bugs/Format/WrongNumberOfFormatArguments

2 files changed

+5
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ class FormatLiteral extends Literal {
900900
*/
901901
int getNumArgNeeded(int n) {
902902
exists(this.getConvSpecOffset(n)) and
903+
exists(this.getConversionChar(n)) and
903904
result = count(int mode | hasFormatArgumentIndexFor(n, mode))
904905
}
905906

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ void test(int i, const char *str)
4242
}
4343

4444
printf("%@ %i %i", 1, 2); // GOOD
45+
46+
printf("%Y", 1, 2); // GOOD (unknown format character, this might be correct)
47+
printf("%1.1Y", 1, 2); // GOOD (unknown format character, this might be correct)
48+
printf("%*.*Y", 1, 2); // GOOD (unknown format character, this might be correct)
4549
}

0 commit comments

Comments
 (0)