diff mbox series

[OpenWrt-Devel] ugps: fix 64-bit time_t

Message ID 20200325055927.131611-1-rosenp@gmail.com
State New
Headers show
Series [OpenWrt-Devel] ugps: fix 64-bit time_t | expand

Commit Message

Rosen Penev March 25, 2020, 5:59 a.m. UTC
The abs function takes a 32-bit int, which can cause truncation. Fixes
compilation error:

error: absolute value function 'abs' given an argu>
if ((sec < 0) || (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET)) {

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 nmea.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/nmea.c b/nmea.c
index 0223b9b..83cb429 100644
--- a/nmea.c
+++ b/nmea.c
@@ -104,7 +104,7 @@  nmea_rmc_cb(void)
 
 			gettimeofday(&cur, NULL);
 
-			if ((sec < 0) || (abs(cur.tv_sec - tv.tv_sec) > MAX_TIME_OFFSET)) {
+			if ((sec < 0) || (llabs(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);