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

This commit is contained in:
Calum Grant
2025-01-28 14:04:33 +00:00
parent 5bfd22e60a
commit 6df8fdc233
3 changed files with 33 additions and 0 deletions

View File

@@ -1 +1,2 @@
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
| tests.c:29:27:29:27 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |

View File

@@ -10,3 +10,21 @@ void f(UNKNOWN_CHAR * str) {
fprintf(0, "%s", ""); // GOOD
printf("%s", str); // GOOD - erroneous type is ignored
}
#define va_list void*
#define va_start(x, y) x = 0;
#define va_arg(x, y) ((y)x)
#define va_end(x)
int vprintf(const char * format, va_list args);
int my_printf(const char * format, ...) {
va_list args;
va_start(args, format);
int result = vprintf(format, args);
va_end(args);
return result;
}
void linker_awareness_test() {
my_printf("%s%d", "", 1); // GOOD
}

View File

@@ -0,0 +1,14 @@
#define va_list void*
#define va_start(x, y) x = 0;
#define va_arg(x, y) ((y)x)
#define va_end(x)
int vprintf(const char * format, va_list args);
int my_printf(void * p,const char * format, ...) {
va_list args;
va_start(args, format);
int result = vprintf(format, args);
va_end(args);
return result;
}