mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: Add test for cpp/wrong-type-format-argument
This commit is contained in:
@@ -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'. |
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user