From f2f7b4dde15c553627a85e2d13f2612552994188 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 28 Jul 2021 12:10:06 +0200 Subject: listen: Fix overzealous GCC warnings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 11 has returned to the old tradition of overzealous warnings. Rewrite the conversion of time in seconds to hours, minutes and seconds to something that not only fixes the warnings but also is more readable. gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -Wall -MT listen.o -MD -MP -MF .deps/listen.Tpo -c -o listen.o listen.c listen.c: In function ‘display_timestamp’: listen.c:73:52: warning: ‘%06u’ directive output may be truncated writing 6 bytes into a region of size between 2 and 7 [-Wformat-truncation=] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~ listen.c:73:36: note: directive argument in the range [0, 999999] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~ listen.c:73:9: note: ‘snprintf’ output between 16 and 21 bytes into a destination of size 16 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 | hours, minutes, seconds, usec); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ listen.c:73:52: warning: ‘%06u’ directive output may be truncated writing 6 bytes into a region of size between 2 and 7 [-Wformat-truncation=] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~ listen.c:73:36: note: directive argument in the range [0, 999999] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~ listen.c:73:9: note: ‘snprintf’ output between 16 and 21 bytes into a destination of size 16 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 | hours, minutes, seconds, usec); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ listen.c:73:52: warning: ‘%06u’ directive output may be truncated writing 6 bytes into a region of size between 2 and 7 [-Wformat-truncation=] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~ listen.c:73:36: note: directive argument in the range [0, 999999] 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~ listen.c:73:9: note: ‘snprintf’ output between 16 and 21 bytes into a destination of size 16 73 | snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%06u", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 | hours, minutes, seconds, usec); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ralf Baechle --- listen/listen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/listen/listen.c b/listen/listen.c index 29fa53f..7053412 100644 --- a/listen/listen.c +++ b/listen/listen.c @@ -52,9 +52,11 @@ static char * ts_format(unsigned int sec, unsigned int usec) static char buf[sizeof("00:00:00.000000")]; unsigned int hours, minutes, seconds; - hours = sec / 3600; - minutes = (sec % 3600) / 60; seconds = sec % 60; + sec = sec / 60; + minutes = sec % 60; + sec = sec / 60; + hours = sec % 24; /* * The real purpose of these checks is to let GCC figure out the -- cgit v1.2.3