From dd5b14301c326a56cb6ca9a0ba66ff28c2c4bd91 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Thu, 22 Sep 2016 07:56:15 -0700
Subject: [PATCH] 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.
---
 src/who.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/who.c b/src/who.c
index f56c718..8d623bc 100644
--- a/src/who.c
+++ b/src/who.c
@@ -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,7 @@ idle_string (time_t when, time_t boottime)
       else
         {
           static char idle_hhmm[IDLESTR_LEN];
+          assert (seconds_idle / (60 * 60) < 24);
           sprintf (idle_hhmm, "%02d:%02d",
                    seconds_idle / (60 * 60),
                    (seconds_idle % (60 * 60)) / 60);
-- 
2.7.4

