Use function format attribute where applicable

Allow the compiler to verify the format string against the supplied
arguments.

    chage.c:239:51: warning: format not a string literal, format string not checked [-Wformat-nonliteral]
      239 |                 (void) strftime (buf, sizeof buf, format, tp);
          |                                                   ^~~~~~
This commit is contained in:
Christian Göttsche
2022-08-05 17:40:42 +02:00
committed by Serge Hallyn
parent 477c8e6f42
commit c6c8130db4
5 changed files with 7 additions and 11 deletions

View File

@@ -320,8 +320,10 @@ extern char *strerror ();
/* To be used for verified unused parameters */
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define unused __attribute__((unused))
# define format_attr(type, index, check) __attribute__((format (type, index, check)))
#else
# define unused
# define format_attr(type, index, check)
#endif
/* ! Arguments evaluated twice ! */

View File

@@ -109,7 +109,7 @@ int reset_selinux_file_context (void)
/*
* Log callback for libselinux internal error reporting.
*/
__attribute__((__format__ (printf, 2, 3)))
format_attr(printf, 2, 3)
static int selinux_log_cb (int type, const char *fmt, ...) {
va_list ap;
char *buf;

View File

@@ -27,6 +27,7 @@
#endif
format_attr(printf, 3, 4)
static void semanage_error_callback (unused void *varg,
semanage_handle_t *handle,
const char *fmt, ...)