From ee0233505bf66742cb8545efd5abcc80f9f9488a Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Wed, 13 Dec 2017 20:12:32 +0100 Subject: [PATCH] canplayer: ensure 6 decimal places in timestamp Ensure the fractions of seconds are 6 decimal places long to catch 3rd party or handcrafted logfiles that treat the timestamp as float. See: https://github.com/linux-can/can-utils/issues/60 Reported-by: https://github.com/hauptmech Signed-off-by: Oliver Hartkopp --- canplayer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/canplayer.c b/canplayer.c index 437ed4b..1d05cad 100644 --- a/canplayer.c +++ b/canplayer.c @@ -477,6 +477,15 @@ int main(int argc, char **argv) return 1; } + /* + * ensure the fractions of seconds are 6 decimal places long to catch + * 3rd party or handcrafted logfiles that treat the timestamp as float + */ + if (strchr(buf, ')') - strchr(buf, '.') != 7) { + fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n"); + return 1; + } + if (use_timestamps) { gettimeofday(&today_tv, NULL);