stat: check if ctime_r() ends in a newline before stripping
authorJens Axboe <axboe@fb.com>
Wed, 21 Sep 2016 03:58:34 +0000 (21:58 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 21 Sep 2016 03:58:34 +0000 (21:58 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
stat.c

diff --git a/stat.c b/stat.c
index c9148ad7a73b321b08751353326e453581fbac59..3c72a6cd8a140b5fe0b81cb9d65d7dc1329a2dfb 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1650,7 +1650,8 @@ void __show_run_stats(void)
 
                os_ctime_r((const time_t *) &now.tv_sec, time_buf,
                                sizeof(time_buf));
-               time_buf[strlen(time_buf) - 1] = '\0';
+               if (time_buf[strlen(time_buf) - 1] == '\n')
+                       time_buf[strlen(time_buf) - 1] = '\0';
 
                root = json_create_object();
                json_object_add_value_string(root, "fio version", fio_version_string);