Skip to content

Commit b911556

Browse files
committed
C++: Add a test showing the motivation.
1 parent d67235b commit b911556

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cpp/ql/test/query-tests/Likely Bugs/Format/WrongNumberOfFormatArguments/WrongNumberOfFormatArguments.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| custom_printf.cpp:29:5:29:12 | call to myPrintf | Format expects 2 arguments but given 1 |
55
| macros.cpp:14:2:14:37 | call to printf | Format expects 4 arguments but given 3 |
66
| macros.cpp:21:2:21:36 | call to printf | Format expects 4 arguments but given 3 |
7+
| macros.cpp:32:2:32:25 | call to printf | Format expects 1 arguments but given 0 |
78
| test.c:9:2:9:7 | call to printf | Format expects 1 arguments but given 0 |
89
| test.c:12:2:12:7 | call to printf | Format expects 2 arguments but given 1 |
910
| test.c:15:2:15:7 | call to printf | Format expects 3 arguments but given 2 |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongNumberOfFormatArguments/macros.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ void testMacros(int a, int b, int c)
2020
BADPRINTF("%i %i %i\n", a, b, c); // GOOD
2121
BADPRINTF("%i %i %i %i\n", a, b, c); // BAD: too few format arguments
2222
}
23+
24+
#define DOTHING(x) \
25+
printf("doing thing: " #x); x
26+
27+
void testMacros2()
28+
{
29+
int x;
30+
31+
DOTHING(x++); // GOOD
32+
DOTHING(printf("%i", x)); // BAD: the printf inside the macro has too few format arguments
33+
}

0 commit comments

Comments
 (0)