...
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 code 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);
|
...
| ISO/IEC TR 24772:2013 | Subprogram Signature Mismatch [OTR] |
| MISRA - C:2012 | Rule 1617.1 (required) |
| MITRE CWE | CWE-628, Function call with incorrectly specified arguments |
...