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

Rosen Penev rosenp at gmail.com
Wed Mar 25 01:59:27 EDT 2020


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 at gmail.com>
---
 nmea.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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);
-- 
2.25.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list