]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Use function format attribute where applicable
authorChristian Göttsche <cgzones@googlemail.com>
Fri, 5 Aug 2022 15:40:42 +0000 (17:40 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Aug 2022 16:27:56 +0000 (11:27 -0500)
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);
          |                                                   ^~~~~~

lib/defines.h
lib/selinux.c
lib/semanage.c
libmisc/copydir.c
src/chage.c

index 55b42bee5f47d6ea20b3f3f6ce5af01e3b403fb3..4a2b90c9e8068e9ec8ad75541a283e7e371b9d6a 100644 (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 ! */
index f97b1fe5b256d49b1c83f9383a9bc1a12e31f873..ad639bd33baebfe26da759a0c960dd6c1798326d 100644 (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;
index 12401608a5c9af972e1bcba7e67baf9d99de7927..54f9962381b77a826e7347f06089a41a715ff1ea 100644 (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, ...)
index a5f1b3daddfadc727303ad10c2bb051e47602e83..2929151db8466d38f1556dccbe9d440bcd01de6a 100644 (file)
@@ -91,7 +91,8 @@ static int fchown_if_needed (int fdst, const struct stat *statp,
 /*
  * error_acl - format the error messages for the ACL and EQ libraries.
  */
-static void error_acl (struct error_context *ctx, const char *fmt, ...)
+format_attr(printf, 2, 3)
+static void error_acl (unused struct error_context *ctx, const char *fmt, ...)
 {
        va_list ap;
        FILE *shadow_logfd = log_get_logfd();
index ced3a3e8a9459492022fa269a5b2c8236120c513..8cf6779421a769f28b636bd2faac206e3c4e1005 100644 (file)
@@ -223,20 +223,12 @@ static void print_date (time_t date)
 {
        struct tm *tp;
        char buf[80];
-       char format[80];
-
-       if (iflg) {
-               (void) snprintf (format, 80, "%%Y-%%m-%%d");
-       }
-       else {
-               (void) snprintf (format, 80, "%%b %%d, %%Y");
-       }
 
        tp = gmtime (&date);
        if (NULL == tp) {
                (void) printf ("time_t: %lu\n", (unsigned long)date);
        } else {
-               (void) strftime (buf, sizeof buf, format, tp);
+               (void) strftime (buf, sizeof buf, iflg ? "%%Y-%%m-%%d" : "%%b %%d, %%Y", tp);
                (void) puts (buf);
        }
 }