summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin2018-07-12 08:05:17 +0000
committerJohn Crispin2018-07-12 08:05:17 +0000
commitb88037b6bf6a6c812183566d96887cb0b201491b (patch)
tree559070c861409224fb5f30033ad5fd43eb01d949
parentccabdf6c235f1e05b2eaf7a418f7e8450652f381 (diff)
downloadugps-b88037b6bf6a6c812183566d96887cb0b201491b.tar.gz
check timegm return code
Signed-off-by: John Crispin <john@phrozen.org>
-rw-r--r--nmea.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/nmea.c b/nmea.c
index 4a49528..7793097 100644
--- a/nmea.c
+++ b/nmea.c
@@ -97,12 +97,14 @@ nmea_rmc_cb(void)
DEBUG(3, "date: %s UTC\n", tmp);
if (adjust_clock) {
- struct timeval tv = { timegm(&tm), 0 };
+ time_t sec = timegm(&tm);
+ struct timeval tv = { 0 };
struct timeval cur;
gettimeofday(&cur, NULL);
- if (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET) {
+ if ((sec < 0) || (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET)) {
+ 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);
/* only set datetime if specified by command line argument! */