stat: Fix a compiler warning in __show_run_stats()
authorBart Van Assche <bart.vanassche@wdc.com>
Mon, 12 Mar 2018 21:16:56 +0000 (14:16 -0700)
committerBart Van Assche <bart.vanassche@wdc.com>
Mon, 12 Mar 2018 21:42:50 +0000 (14:42 -0700)
Avoid that gcc reports the following warning on NetBSD systems:

    CC stat.o
stat.c: In function '__show_run_stats':
stat.c:1868: warning: dereferencing type-punned pointer will break strict-aliasing rules

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
stat.c

diff --git a/stat.c b/stat.c
index f89913ba3b8a057e9fef4ff061d72ad4c006479d..8a242c97430bd0bff2502013af5fd848a2a57881 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1860,13 +1860,14 @@ void __show_run_stats(void)
                char time_buf[32];
                struct timeval now;
                unsigned long long ms_since_epoch;
+               time_t tv_sec;
 
                gettimeofday(&now, NULL);
                ms_since_epoch = (unsigned long long)(now.tv_sec) * 1000 +
                                 (unsigned long long)(now.tv_usec) / 1000;
 
-               os_ctime_r((const time_t *) &now.tv_sec, time_buf,
-                               sizeof(time_buf));
+               tv_sec = now.tv_sec;
+               os_ctime_r(&tv_sec, time_buf, sizeof(time_buf));
                if (time_buf[strlen(time_buf) - 1] == '\n')
                        time_buf[strlen(time_buf) - 1] = '\0';