C++: Make specsAreKnown more accurate.

This commit is contained in:
Geoffrey White
2020-12-15 17:12:49 +00:00
parent 676e85a155
commit 93dfeac3c8
3 changed files with 4 additions and 6 deletions

View File

@@ -900,6 +900,7 @@ class FormatLiteral extends Literal {
*/
int getNumArgNeeded(int n) {
exists(this.getConvSpecOffset(n)) and
exists(this.getConversionChar(n)) and
result = count(int mode | hasFormatArgumentIndexFor(n, mode))
}

View File

@@ -12,6 +12,3 @@
| test.c:39:3:39:8 | call to printf | Format expects 2 arguments but given 5 |
| test.c:40:3:40:8 | call to printf | Format expects 2 arguments but given 4 |
| test.c:41:3:41:8 | call to printf | Format expects 2 arguments but given 3 |
| test.c:46:2:46:7 | call to printf | Format expects 1 arguments but given 2 |
| test.c:47:2:47:7 | call to printf | Format expects 1 arguments but given 2 |
| test.c:48:2:48:7 | call to printf | Format expects 1 arguments but given 2 |

View File

@@ -43,7 +43,7 @@ void test(int i, const char *str)
printf("%@ %i %i", 1, 2); // GOOD
printf("%Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
printf("%1.1Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
printf("%*.*Y", 1, 2); // GOOD (unknown format character, this might be correct) [FALSE POSITIVE]
printf("%Y", 1, 2); // GOOD (unknown format character, this might be correct)
printf("%1.1Y", 1, 2); // GOOD (unknown format character, this might be correct)
printf("%*.*Y", 1, 2); // GOOD (unknown format character, this might be correct)
}