C++: Add test for cpp/wrong-type-format-argument

This commit is contained in:
Calum Grant
2024-10-15 13:57:57 +01:00
committed by Calum Grant
parent 886c7f1f7a
commit fe85e007b3
3 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
| tests.c:8:18:8:34 | call to implicit_function | This format specifier for type 'char *' does not match the argument type 'int'. |
| tests.c:9:13:9:13 | 0 | This format specifier for type 'char *' does not match the argument type 'int'. |
| tests.c:10:13:10:13 | 0 | This format specifier for type 'char *' does not match the argument type 'int'. |

View File

@@ -0,0 +1 @@
Likely Bugs/Format/WrongTypeFormatArguments.ql

View File

@@ -0,0 +1,11 @@
// semmle-extractor-options: --expect_errors
int printf(const char * format, ...);
int fprintf();
int f() {
printf("%s", 1); // BAD - TP
printf("%s", implicit_function()); // BAD (FP) - we should not infer the return type
sprintf(0, "%s", ""); // BAD (FP)
fprintf(0, "%s", ""); // BAD (FP)
}