diff options
| author | Daniel Golle | 2020-04-29 17:14:16 +0000 |
|---|---|---|
| committer | Daniel Golle | 2020-04-29 17:56:02 +0000 |
| commit | db40e3a22599641be68c88ece287d3fbbacd8a45 (patch) | |
| tree | d9e22f120331248b46d000e0cf0ce2985b1ab0d7 | |
| parent | cd7eabcd8c9d17dab3946002127a82ad2f9e68c2 (diff) | |
| download | ugps-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.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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); |