summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2021-07-28 12:10:06 +0200
committerRalf Baechle <ralf@linux-mips.org>2021-07-28 12:10:06 +0200
commitf2f7b4dde15c553627a85e2d13f2612552994188 (patch)
tree737317956d964d9dd4dc8f144240d0af62e9a678
parent91a2475f102973ef999f7ee6eddc6b4b1631fc4f (diff)
listen: Fix overzealous GCC warnings.
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 <ralf@linux-mips.org>
-rw-r--r--listen/listen.c6
1 files 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