...
In this noncompliant code example, the average()
function is called as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
int avg = average(1, 4, 6, 4, 1); |
...
This compliant solution enforces the contract by adding va_eol
as the final argument.
Code Block | ||||
---|---|---|---|---|
| ||||
int avg = average(1, 4, 6, 4, 1, va_eol); |
...
Another common mistake is to use more conversion specifiers than supplied arguments, as shown in this noncompliant coding example.
Code Block | ||||
---|---|---|---|---|
| ||||
const char *error_msg = "Resource not available to user."; /* ... */ printf("Error (%s): %s", error_msg); |
...
This compliant solution matches the number of format specifiers with the number of variable arguments.
Code Block | ||||
---|---|---|---|---|
| ||||
const char *error_msg = "Resource not available to user."; /* ... */ printf("Error: %s", error_msg); |
...