Skip to content

Commit 6df8fdc

Browse files
committed
C++: Add test for cpp/wrong-type-format-argument
1 parent 5bfd22e commit 6df8fdc

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
2+
| tests.c:29:27:29:27 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,21 @@ void f(UNKNOWN_CHAR * str) {
1010
fprintf(0, "%s", ""); // GOOD
1111
printf("%s", str); // GOOD - erroneous type is ignored
1212
}
13+
14+
#define va_list void*
15+
#define va_start(x, y) x = 0;
16+
#define va_arg(x, y) ((y)x)
17+
#define va_end(x)
18+
int vprintf(const char * format, va_list args);
19+
20+
int my_printf(const char * format, ...) {
21+
va_list args;
22+
va_start(args, format);
23+
int result = vprintf(format, args);
24+
va_end(args);
25+
return result;
26+
}
27+
28+
void linker_awareness_test() {
29+
my_printf("%s%d", "", 1); // GOOD
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#define va_list void*
2+
#define va_start(x, y) x = 0;
3+
#define va_arg(x, y) ((y)x)
4+
#define va_end(x)
5+
6+
int vprintf(const char * format, va_list args);
7+
8+
int my_printf(void * p,const char * format, ...) {
9+
va_list args;
10+
va_start(args, format);
11+
int result = vprintf(format, args);
12+
va_end(args);
13+
return result;
14+
}

0 commit comments

Comments
 (0)