]> granicus.if.org Git - sudo/commitdiff
Quiet some gcc -Wformat=2 false positives
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 19 Aug 2013 12:39:33 +0000 (06:39 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 19 Aug 2013 12:39:33 +0000 (06:39 -0600)
plugins/sudoers/timestr.c
plugins/sudoers/visudo.c

index b2df41b12b6d4270bf68a4c52fa9da68a45f36af..9b89a1da86ad16aec0d430c9a95ffe9e35cb82ef 100644 (file)
@@ -33,7 +33,7 @@
 char *get_timestr(time_t, int);
 
 /*
- * Return an ascii string with the current date + time
+ * Return a static buffer with the current date + time.
  * Uses strftime() if available, else falls back to ctime().
  */
 char *
@@ -45,14 +45,11 @@ get_timestr(time_t tstamp, int log_year)
     struct tm *timeptr;
 
     timeptr = localtime(&tstamp);
-    if (log_year)
-       s = "%h %e %T %Y";
-    else
-       s = "%h %e %T";
 
     /* strftime() does not guarantee to NUL-terminate so we must check. */
     buf[sizeof(buf) - 1] = '\0';
-    if (strftime(buf, sizeof(buf), s, timeptr) && buf[sizeof(buf) - 1] == '\0')
+    if (strftime(buf, sizeof(buf), log_year ? "%h %e %T %Y" : "%h %e %T",
+       timeptr) != 0 && buf[sizeof(buf) - 1] == '\0')
        return buf;
 
 #endif /* HAVE_STRFTIME */
index 983eaa5b2416b901f5a3fdf91c40099801c58306..e58fca0cd58354711ebb6b3e5da99e2825d8a524 100644 (file)
@@ -1111,20 +1111,21 @@ check_alias(char *name, int type, int strict, int quiet)
        alias_put(a);
     } else {
        if (!quiet) {
-           char *fmt;
            if (errno == ELOOP) {
-               fmt = strict ?
+               warningx(strict ?
                    _("Error: cycle in %s_Alias `%s'") :
-                   _("Warning: cycle in %s_Alias `%s'");
+                   _("Warning: cycle in %s_Alias `%s'"),
+                   type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" :
+                   type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" :
+                   "Unknown", name);
            } else {
-               fmt = strict ?
+               warningx(strict ?
                    _("Error: %s_Alias `%s' referenced but not defined") :
-                   _("Warning: %s_Alias `%s' referenced but not defined");
+                   _("Warning: %s_Alias `%s' referenced but not defined"),
+                   type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" :
+                   type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" :
+                   "Unknown", name);
            }
-           warningx(fmt,
-               type == HOSTALIAS ? "Host" : type == CMNDALIAS ? "Cmnd" :
-               type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" :
-               "Unknown", name);
        }
        errors++;
     }