nmea: fix time comparision
authorDaniel Golle <daniel@makrotopia.org>
Wed, 29 Apr 2020 17:14:16 +0000 (18:14 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 29 Apr 2020 17:56:02 +0000 (18:56 +0100)
Code introduced by commit b88037b ("check timegm return code") compares
GPS-time with tv_sec of freshly zero-initialized struct timeval tv.
Compare with current time instead.

Fixes: b88037b ("check timegm return code")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
nmea.c

diff --git a/nmea.c b/nmea.c
index 0223b9bbfae9a157bad9f5bfb91c46b1a2d8608d..61c57ab883da6e47897306885c923e2b90a23878 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -99,12 +99,12 @@ nmea_rmc_cb(void)
 
                if (adjust_clock) {
                        time_t sec = timegm(&tm);
-                       struct timeval tv = { 0 };
                        struct timeval cur;
 
                        gettimeofday(&cur, NULL);
 
-                       if ((sec < 0) || (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET)) {
+                       if ((sec < 0) || (abs(cur.tv_sec - sec) > MAX_TIME_OFFSET)) {
+                               struct timeval tv = { 0 };
                                tv.tv_sec = sec;
                                if (++nmea_bad_time > MAX_BAD_TIME) {
                                        LOG("system time differs from GPS time by more than %d seconds. Using %s UTC as the new time\n", MAX_TIME_OFFSET, tmp);