ugps: fix 64-bit time_t
authorRosen Penev <rosenp@gmail.com>
Tue, 21 Jul 2020 22:50:37 +0000 (15:50 -0700)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 29 Aug 2020 10:06:15 +0000 (11:06 +0100)
The abs function takes a 32-bit int, which can cause truncation. Fixes
compilation error:

error: absolute value function 'abs' given an argu>
if ((sec < 0) || (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET)) {

Signed-off-by: Rosen Penev <rosenp@gmail.com>
nmea.c

diff --git a/nmea.c b/nmea.c
index 8df77929f422dfe17d3625da8d8c6f622b899867..1204c20f61eb444bf0b58b2f95c14d807c527307 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -107,7 +107,7 @@ nmea_rmc_cb(void)
 
                        gettimeofday(&cur, NULL);
 
-                       if ((sec < 0) || (abs(cur.tv_sec - sec) > MAX_TIME_OFFSET)) {
+                       if ((sec < 0) || (llabs(cur.tv_sec - sec) > MAX_TIME_OFFSET)) {
                                struct timeval tv = { 0 };
                                tv.tv_sec = sec;
                                if (++nmea_bad_time > MAX_BAD_TIME) {