CERT-FIO47-C_b
In this section:
Synopsis
Use valid format strings.
Enabled by default
Yes
Severity/Certainty
High/Low

Full description
The formatted output functions (fprintf() and related functions) convert, format, and print their arguments under control of a format string. The C standard outlines what format specifiers are valid in a format string. This check will find cases where the types of the arguments to a format string function do not match the format string specifiers.
Coding standards
- CERT FIO47-C
Use valid format strings
Code examples
The following code example fails the check and will give a warning:
#include <stdio.h>
void func(void) {
const char *error_msg = "Resource not available to user.";
int error_type = 3;
/* ... */
printf("Error (type %s): %d\n", error_type, error_msg);
/* ... */
}
The following code example passes the check and will not give a warning about this issue:
#include <stdio.h>
void func(void) {
const char *error_msg = "Resource not available to user.";
int error_type = 3;
/* ... */
printf("Error (type %d): %s\n", error_type, error_msg);
/* ... */
}