From: Daniel Golle Date: Wed, 29 Apr 2020 17:14:16 +0000 (+0100) Subject: nmea: fix time comparision X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=db40e3a22599641be68c88ece287d3fbbacd8a45;p=project%2Fugps.git nmea: fix time comparision 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 --- diff --git a/nmea.c b/nmea.c index 0223b9b..61c57ab 100644 --- 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);