aboutsummaryrefslogblamecommitdiffstats
path: root/main/dovecot/0001-lib-time-util-Fix-calculations-to-work-on-32-bit-sys.patch
blob: 3c494b40c5c9f4fe75e165ebe88e19c2386e291e (plain) (tree)
















































                                                                                         
From b715149395814fc1f77da2d52f74a635854efd49 Mon Sep 17 00:00:00 2001
From: Aki Tuomi <aki.tuomi@open-xchange.com>
Date: Mon, 18 Jan 2021 17:38:15 +0200
Subject: [PATCH] lib: time-util - Fix calculations to work on 32-bit systems

Broken by 16ab55427a727d3c93046367f7ae582c9f744458
---
 src/lib/time-util.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/lib/time-util.c b/src/lib/time-util.c
index 294bb02310..c9ff4a5b62 100644
--- a/src/lib/time-util.c
+++ b/src/lib/time-util.c
@@ -38,22 +38,24 @@ int timeval_cmp(const struct timeval *tv1, const struct timeval *tv2)
 int timeval_cmp_margin(const struct timeval *tv1, const struct timeval *tv2,
 	unsigned int usec_margin)
 {
-	long long usecs_diff;
+	long long usecs_diff, secs_diff;
 	int sec_margin, ret;
 
 	if (tv1->tv_sec < tv2->tv_sec) {
+		secs_diff = (long long)tv2->tv_sec - (long long)tv1->tv_sec;
+		usecs_diff = tv2->tv_usec - tv1->tv_usec;
 		sec_margin = ((int)usec_margin / 1000000) + 1;
-		if ((tv2->tv_sec - tv1->tv_sec) > sec_margin)
+		if (secs_diff > sec_margin)
 			return -1;
-		usecs_diff = (tv2->tv_sec - tv1->tv_sec) * 1000000LL +
-			(tv2->tv_usec - tv1->tv_usec);
+		usecs_diff = secs_diff * 1000000LL + usecs_diff;
 		ret = -1;
 	} else if (tv1->tv_sec > tv2->tv_sec) {
+		secs_diff = (long long)tv1->tv_sec - (long long)tv2->tv_sec;
+		usecs_diff = tv1->tv_usec - tv2->tv_usec;
 		sec_margin = ((int)usec_margin / 1000000) + 1;
-		if ((tv1->tv_sec - tv2->tv_sec) > sec_margin)
+		if (secs_diff > sec_margin)
 			return 1;
-		usecs_diff = (tv1->tv_sec - tv2->tv_sec) * 1000000LL +
-			(tv1->tv_usec - tv2->tv_usec);
+		usecs_diff = secs_diff * 1000000LL + usecs_diff;
 		ret = 1;
 	} else if (tv1->tv_usec < tv2->tv_usec) {
 		usecs_diff = tv2->tv_usec - tv1->tv_usec;
-- 
2.20.1