Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, the average() function is called as follows:

Code Block
bgColor#ffcccc
langc
int avg = average(1, 4, 6, 4, 1);

...

This compliant solution enforces the contract by adding va_eol as the final argument.

Code Block
bgColor#ccccff
langc
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
bgColor#ffcccc
langc
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
bgColor#ccccff
langc
const char *error_msg = "Resource not available to user.";
/* ... */
printf("Error: %s", error_msg);

...