Skip to content

Commit 6a0212e

Browse files
committed
C++: Add regression test
1 parent 297d321 commit 6a0212e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
| test.c:15:2:15:7 | call to printf | Format for printf expects 3 arguments but given 2 |
1111
| test.c:19:2:19:7 | call to printf | Format for printf expects 2 arguments but given 1 |
1212
| test.c:29:3:29:8 | call to printf | Format for printf expects 2 arguments but given 1 |
13+
| test.c:51:2:51:10 | call to my_logger | Format for my_logger expects 6 arguments but given 1 |
14+
| test.c:52:2:52:10 | call to my_logger | Format for my_logger expects 3 arguments but given 0 |
15+
| test.c:53:2:53:10 | call to my_logger | Format for my_logger expects 3 arguments but given 0 |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ void test_custom_printf2()
4444
printf("", "%i %i", 100, 200); // GOOD
4545
printf("%i %i", "" ); // GOOD
4646
}
47+
48+
extern "C" void my_logger(int param, char *fmt, ...) __attribute__((format(printf, 2, 3))) {}
49+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ void test(int i, const char *str)
4646
printf("%Y", 1, 2); // GOOD (unknown format character, this might be correct)
4747
printf("%1.1Y", 1, 2); // GOOD (unknown format character, this might be correct)
4848
printf("%*.*Y", 1, 2); // GOOD (unknown format character, this might be correct)
49+
50+
// Implicit logger function declaration
51+
my_logger(0, "%i %i %i %i %i %i\n", 1, 2, 3, 4, 5, 6); // GOOD (FP)
52+
my_logger(0, "%i %i %i\n", 1, 2, 3); // GOOD (FP)
53+
my_logger(0, "%i %i %i\n", 1, 2); // BAD (too few format arguments)
4954
}
55+
56+
// A spurious definition of my_logger
57+
extern void my_logger(int param, char *fmt, int, int, int, int, int);

0 commit comments

Comments
 (0)