Skip to content

Commit 93dfeac

Browse files
committed
C++: Make specsAreKnown more accurate.
1 parent 676e85a commit 93dfeac

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
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/TooManyFormatArguments.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@
1212
| test.c:39:3:39:8 | call to printf | Format expects 2 arguments but given 5 |
1313
| test.c:40:3:40:8 | call to printf | Format expects 2 arguments but given 4 |
1414
| test.c:41:3:41:8 | call to printf | Format expects 2 arguments but given 3 |
15-
| test.c:46:2:46:7 | call to printf | Format expects 1 arguments but given 2 |
16-
| test.c:47:2:47:7 | call to printf | Format expects 1 arguments but given 2 |
17-
| test.c:48:2:48:7 | call to printf | Format expects 1 arguments but given 2 |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void test(int i, const char *str)
4343

4444
printf("%@ %i %i", 1, 2); // GOOD
4545

46-
printf("%Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
47-
printf("%1.1Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
48-
printf("%*.*Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
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)
4949
}

0 commit comments

Comments
 (0)