C++: Add a test of unknown format specifiers (with specsAreKnown check disabled).

This commit is contained in:
Geoffrey White
2020-12-15 17:37:36 +00:00
parent ceaaac217e
commit 94dea9f71d
3 changed files with 8 additions and 1 deletions

View File

@@ -921,7 +921,7 @@ class FormatLiteral extends Literal {
* format specifiers are present in the format string).
*/
predicate specsAreKnown() {
this.getNumConvSpec() = count(int n | exists(this.getNumArgNeeded(n)))
any()
}
/**

View File

@@ -12,3 +12,6 @@
| 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

@@ -42,4 +42,8 @@ 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]
}