From 3e4c91bee66ba2a6dedea8a0f258871954b58b9b Mon Sep 17 00:00:00 2001 From: Ilya Bakhtin Date: Fri, 29 Sep 2023 16:23:04 +0200 Subject: [PATCH] util/time: Prevent usecs overflow This commit takes care of original seconds value and prevents the useconds field from overflowing pas its maximum value. Issue: 6372 (cherry picked from commit d3095ac0589228a4c63a466f5ff3b99bab98bf25) --- src/util-time.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util-time.h b/src/util-time.h index 9bbd8798dd..479f9a2b35 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -57,7 +57,11 @@ typedef struct { #define SCTIME_SECS(t) ((uint64_t)(t).secs) #define SCTIME_MSECS(t) (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000) #define SCTIME_ADD_SECS(ts, s) SCTIME_FROM_SECS((ts).secs + (s)) -#define SCTIME_ADD_USECS(ts, us) SCTIME_FROM_USECS((ts).usecs + (us)) +#define SCTIME_ADD_USECS(ts, us) \ + (SCTime_t) \ + { \ + .secs = (ts).secs + ((ts).usecs + (us)) / 1000000, .usecs = ((ts).usecs + (us)) % 1000000 \ + } #define SCTIME_FROM_SECS(s) \ (SCTime_t) \ { \ -- 2.47.3