From: Todd C. Miller Date: Mon, 19 Aug 2013 12:39:33 +0000 (-0600) Subject: Quiet some gcc -Wformat=2 false positives X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd589f23423b22f456fb58de4fadc3d4f570a892;p=sudo Quiet some gcc -Wformat=2 false positives --- diff --git a/plugins/sudoers/timestr.c b/plugins/sudoers/timestr.c index b2df41b12..9b89a1da8 100644 --- a/plugins/sudoers/timestr.c +++ b/plugins/sudoers/timestr.c @@ -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 */ diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 983eaa5b2..e58fca0cd 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -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++; }