mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
CPP: Test for WrongTypeFormatArguments with multiple definitions.
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
| a.c:13:39:13:42 | 1.0 | This argument should be of type 'char *' but is of type 'double' |
|
||||
| a.c:13:39:13:42 | 1.0 | This argument should be of type 'int' but is of type 'double' |
|
||||
| a.c:15:40:15:43 | 1.0 | This argument should be of type 'char *' but is of type 'double' |
|
||||
| a.c:15:40:15:43 | 1.0 | This argument should be of type 'int' but is of type 'double' |
|
||||
| format.h:16:59:16:61 | str | This argument should be of type 'int' but is of type 'char *' |
|
||||
| format.h:16:64:16:64 | i | This argument should be of type 'double' but is of type 'int' |
|
||||
| format.h:16:67:16:67 | d | This argument should be of type 'char *' but is of type 'double' |
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
__attribute__((format(printf, 1, 3)))
|
||||
void myMultiplyDefinedPrintf(const char *format, const char *extraArg, ...)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
__attribute__((format(printf, 1, 3)))
|
||||
void myMultiplyDefinedPrintf2(const char *format, const char *extraArg, ...);
|
||||
|
||||
void test_custom_printf1()
|
||||
{
|
||||
myMultiplyDefinedPrintf("%i", "%s", 1); // GOOD
|
||||
myMultiplyDefinedPrintf("%i", "%s", 1.0f); // BAD
|
||||
myMultiplyDefinedPrintf2("%i", "%s", 1); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2("%i", "%s", 1.0f); // GOOD (we can't tell which definition is correct so we have to assume this is OK) [FALSE POSITIVE]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void myMultiplyDefinedPrintf(const char *extraArg, const char *format, ...); // this declaration does not match the definition
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void myMultiplyDefinedPrintf2(const char *extraArg, const char *format, ...);
|
||||
|
||||
void test_custom_printf2()
|
||||
{
|
||||
myMultiplyDefinedPrintf("%i", "%f", 1); // GOOD
|
||||
myMultiplyDefinedPrintf("%i", "%f", 1.0f); // BAD [NOT DETECTED]
|
||||
myMultiplyDefinedPrintf2("%i", "%f", 1); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2("%i", "%f", 1.0f); // GOOD (we can't tell which definition is correct so we have to assume this is OK)
|
||||
}
|
||||
Reference in New Issue
Block a user