|
| 1 | + |
| 2 | +__attribute__((format(printf, 1, 3))) |
| 3 | +void myMultiplyDefinedPrintf(const char *format, int extraArg, ...) |
| 4 | +{ |
| 5 | + // ... |
| 6 | +} |
| 7 | + |
| 8 | +__attribute__((format(printf, 1, 3))) |
| 9 | +void myMultiplyDefinedPrintf2(const char *format, int extraArg, ...); |
| 10 | + |
| 11 | +__attribute__((format(printf, 2, 3))) |
| 12 | +void myMultiplyDefinedPrintf3(const char *extraArg, const char *format, ...); |
| 13 | + |
| 14 | +void test_custom_printf1() |
| 15 | +{ |
| 16 | + myMultiplyDefinedPrintf("%i", 0); // BAD (too few format arguments) |
| 17 | + myMultiplyDefinedPrintf("%i", 0, 1); // GOOD |
| 18 | + myMultiplyDefinedPrintf("%i", 0, 1, 2); // BAD (too many format arguments) |
| 19 | + myMultiplyDefinedPrintf2("%i", 0); // GOOD (we can't tell which definition is correct so we have to assume this is OK) |
| 20 | + myMultiplyDefinedPrintf2("%i", 0, 1); // GOOD (we can't tell which definition is correct so we have to assume this is OK) |
| 21 | + myMultiplyDefinedPrintf2("%i", 0, 1, 2); // BAD (too many format arguments regardless of which definition is correct) [NOT DETECTED] |
| 22 | + myMultiplyDefinedPrintf3("%s", "%s"); // GOOD (we can't tell which definition is correct so we have to assume this is OK) |
| 23 | + myMultiplyDefinedPrintf3("%s", "%s", "%s"); // GOOD (we can't tell which definition is correct so we have to assume this is OK) |
| 24 | + myMultiplyDefinedPrintf3("%s", "%s", "%s", "%s"); // BAD (too many format arguments regardless of which definition is correct) [NOT DETECTED] |
| 25 | +} |
0 commit comments