fix timeval to ASCII unsigned value conversion

As reported by Oleksij Rempel here
https://github.com/linux-can/can-utils/issues/233#issuecomment-674818935
the representation of timeval timestamps are signed values which leads to
negative values on 32 bit machines addressing the year 2038 unix sec counter
overflow.

Fix the issue on 32 bit systems by converting the timeval values to unsigned
ASCII value representations.

Fixes: https://github.com/linux-can/can-utils/issues/234
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2020-08-18 12:51:35 +02:00
parent ab23c6f7e7
commit a4905ed7c8
8 changed files with 28 additions and 28 deletions
+3 -3
View File
@@ -101,7 +101,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
printf("(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
break;
case 'A': /* absolute with date */
@@ -111,7 +111,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
tm = *localtime(&tv->tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
printf("(%s.%06ld) ", timestring, tv->tv_usec);
printf("(%s.%06lu) ", timestring, tv->tv_usec);
}
break;
@@ -128,7 +128,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%ld.%06ld) ", diff.tv_sec, diff.tv_usec);
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
if (timestamp == 'd')
*last_tv = *tv; /* update for delta calculation */