Skip to content

Commit 144cda7

Browse files
committed
CPP: Test for WrongTypeFormatArguments with multiple definitions.
1 parent 9986de8 commit 144cda7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
| a.c:13:39:13:42 | 1.0 | This argument should be of type 'char *' but is of type 'double' |
2+
| a.c:13:39:13:42 | 1.0 | This argument should be of type 'int' but is of type 'double' |
3+
| a.c:15:40:15:43 | 1.0 | This argument should be of type 'char *' but is of type 'double' |
4+
| a.c:15:40:15:43 | 1.0 | This argument should be of type 'int' but is of type 'double' |
15
| format.h:16:59:16:61 | str | This argument should be of type 'int' but is of type 'char *' |
26
| format.h:16:64:16:64 | i | This argument should be of type 'double' but is of type 'int' |
37
| format.h:16:67:16:67 | d | This argument should be of type 'char *' but is of type 'double' |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
__attribute__((format(printf, 1, 3)))
3+
void myMultiplyDefinedPrintf(const char *format, const char *extraArg, ...)
4+
{
5+
// ...
6+
}
7+
__attribute__((format(printf, 1, 3)))
8+
void myMultiplyDefinedPrintf2(const char *format, const char *extraArg, ...);
9+
10+
void test_custom_printf1()
11+
{
12+
myMultiplyDefinedPrintf("%i", "%s", 1); // GOOD
13+
myMultiplyDefinedPrintf("%i", "%s", 1.0f); // BAD
14+
myMultiplyDefinedPrintf2("%i", "%s", 1); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
15+
myMultiplyDefinedPrintf2("%i", "%s", 1.0f); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
__attribute__((format(printf, 2, 3)))
3+
void myMultiplyDefinedPrintf(const char *extraArg, const char *format, ...); // this declaration does not match the definition
4+
5+
__attribute__((format(printf, 2, 3)))
6+
void myMultiplyDefinedPrintf2(const char *extraArg, const char *format, ...);
7+
8+
void test_custom_printf2()
9+
{
10+
myMultiplyDefinedPrintf("%i", "%f", 1); // GOOD
11+
myMultiplyDefinedPrintf("%i", "%f", 1.0f); // BAD [NOT DETECTED]
12+
myMultiplyDefinedPrintf2("%i", "%f", 1); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
13+
myMultiplyDefinedPrintf2("%i", "%f", 1.0f); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
14+
}

0 commit comments

Comments
 (0)