mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Merge pull request #2003 from geoffw0/formatarg
CPP: WrongTypeFormatArguments.ql Fix
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
|
||||
__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, ...);
|
||||
|
||||
char *getString();
|
||||
|
||||
void test_custom_printf1()
|
||||
{
|
||||
myMultiplyDefinedPrintf("string", getString()); // GOOD
|
||||
myMultiplyDefinedPrintf(getString(), "string"); // BAD [NOT DETECTED]
|
||||
myMultiplyDefinedPrintf2("string", getString()); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2(getString(), "string"); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
__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, ...);
|
||||
|
||||
char *getString();
|
||||
|
||||
void test_custom_printf2(char *string)
|
||||
{
|
||||
myMultiplyDefinedPrintf("string", getString()); // GOOD
|
||||
myMultiplyDefinedPrintf(getString(), "string"); // BAD [NOT DETECTED]
|
||||
myMultiplyDefinedPrintf2("string", getString()); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2(getString(), "string"); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
}
|
||||
@@ -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", "%f", 1); // GOOD
|
||||
myMultiplyDefinedPrintf("%i", "%f", 1.0f); // BAD [NOT DETECTED]
|
||||
myMultiplyDefinedPrintf2("%i", "%f", 1); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2("%i", "%f", 1.0f); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
}
|
||||
@@ -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 declaration is correct so we have to assume this is OK)
|
||||
myMultiplyDefinedPrintf2("%i", "%f", 1.0f); // GOOD (we can't tell which declaration is correct so we have to assume this is OK)
|
||||
}
|
||||
Reference in New Issue
Block a user