From: Jim Meyering Date: Thu, 22 Sep 2016 14:56:15 +0000 (-0700) Subject: who: avoid new warning from upcoming gcc-7 X-Git-Tag: v8.26~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb406b2caf4d6307d7f86f38da4d6029a6b83961;p=thirdparty%2Fcoreutils.git who: avoid new warning from upcoming gcc-7 * src/who.c (idle_string): This function would fail to compile with -Werror and today's built-from-git gcc due to this warning: src/who.c: In function 'print_user': src/who.c:201:36: error: may write format character ':' at offset 4 \ past the end of the destination [-Werror=format-length=] sprintf (idle_hhmm, "%02d:%02d", ^~~~~ The fix is to use an assertion to inform gcc of the existing invariant that guarantees the number of hours is less than 24. --- diff --git a/src/who.c b/src/who.c index f56c718332..d5f5732558 100644 --- a/src/who.c +++ b/src/who.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "system.h" @@ -198,6 +199,9 @@ idle_string (time_t when, time_t boottime) else { static char idle_hhmm[IDLESTR_LEN]; + /* FIXME-in-2018: see if this assert is still required in order + to suppress gcc's unwarranted -Wformat-length= warning. */ + assert (seconds_idle / (60 * 60) < 24); sprintf (idle_hhmm, "%02d:%02d", seconds_idle / (60 * 60), (seconds_idle % (60 * 60)) / 60);