diff options
author | Jim Meyering <meyering@fb.com> | 2016-09-22 07:56:15 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2016-09-22 10:17:07 -0700 |
commit | eb406b2caf4d6307d7f86f38da4d6029a6b83961 (patch) | |
tree | d26a1e3230057fd8d55a696a7deef6bccd8a1bc6 /src/who.c | |
parent | 1db94ee969b984bbd00b97c6abbe2f69db8e0000 (diff) | |
download | coreutils-eb406b2caf4d6307d7f86f38da4d6029a6b83961.tar.xz |
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.
Diffstat (limited to 'src/who.c')
-rw-r--r-- | src/who.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -26,6 +26,7 @@ #include <config.h> #include <getopt.h> #include <stdio.h> +#include <assert.h> #include <sys/types.h> #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); |