summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Golle2020-04-29 17:14:16 +0000
committerDaniel Golle2020-04-29 17:56:02 +0000
commitdb40e3a22599641be68c88ece287d3fbbacd8a45 (patch)
treed9e22f120331248b46d000e0cf0ce2985b1ab0d7
parentcd7eabcd8c9d17dab3946002127a82ad2f9e68c2 (diff)
downloadugps-db40e3a22599641be68c88ece287d3fbbacd8a45.tar.gz
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 <daniel@makrotopia.org>
-rw-r--r--nmea.c4
1 files changed, 2 insertions, 2 deletions
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);