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 <socketcan@hartkopp.net>
pull/62/head
Oliver Hartkopp 2017-12-13 20:12:32 +01:00
parent 33640c8643
commit ee0233505b
1 changed files with 9 additions and 0 deletions

View File

@ -477,6 +477,15 @@ int main(int argc, char **argv)
return 1; 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) { if (use_timestamps) {
gettimeofday(&today_tv, NULL); gettimeofday(&today_tv, NULL);