]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: timeval_add/sub_usecs() - Fix usecs type
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Feb 2026 11:20:39 +0000 (13:20 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Feb 2026 11:25:14 +0000 (13:25 +0200)
Some callers expect it to be 64bit, but suseconds_t isn't guaranteed to be.
Added assert mainly to catch callers that try to provide negative values
as parameter, which wrap to large unsigned values.

src/lib/time-util.h

index 00516b11b5453609d00f5b39188a50b79f6306db..6a0b30d7baee984e1408595ea34b152408459c43 100644 (file)
@@ -35,9 +35,9 @@ timeval_from_usecs(struct timeval *tv_r, unsigned long usecs)
 }
 
 static inline void
-timeval_add_usecs(struct timeval *tv, suseconds_t usecs)
+timeval_add_usecs(struct timeval *tv, unsigned long long usecs)
 {
-       i_assert(usecs >= 0);
+       i_assert(usecs <= LLONG_MAX);
        tv->tv_sec += (time_t)(usecs / 1000000);
        tv->tv_usec += (usecs % 1000000);
        if (tv->tv_usec >= 1000000) {
@@ -47,9 +47,9 @@ timeval_add_usecs(struct timeval *tv, suseconds_t usecs)
 }
 
 static inline void
-timeval_sub_usecs(struct timeval *tv, suseconds_t usecs)
+timeval_sub_usecs(struct timeval *tv, unsigned long long usecs)
 {
-       i_assert(usecs >= 0);
+       i_assert(usecs <= LLONG_MAX);
        tv->tv_sec -= (time_t)(usecs / 1000000);
        tv->tv_usec -= (usecs % 1000000);
        if (tv->tv_usec < 0) {