From: Timo Sirainen Date: Sat, 17 Aug 2019 10:43:21 +0000 (+0300) Subject: lib: timeval_add/sub_usecs() - Add assert to make sure negative values aren't used X-Git-Tag: 2.3.9~304 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e42929088c984942295b60ef6ac00ea0f775aea;p=thirdparty%2Fdovecot%2Fcore.git lib: timeval_add/sub_usecs() - Add assert to make sure negative values aren't used The current code doesn't work correctly if negative values are used. The code could of course be changed to handle them, but maybe assert is better to catch bugs. --- diff --git a/src/lib/time-util.h b/src/lib/time-util.h index f86fa1b730..33ddbd9c46 100644 --- a/src/lib/time-util.h +++ b/src/lib/time-util.h @@ -17,6 +17,7 @@ long long timeval_diff_usecs(const struct timeval *tv1, static inline void timeval_add_usecs(struct timeval *tv, long long usecs) { + i_assert(usecs >= 0); tv->tv_sec += usecs / 1000000; tv->tv_usec += (usecs % 1000000); if (tv->tv_usec >= 1000000) { @@ -28,6 +29,7 @@ timeval_add_usecs(struct timeval *tv, long long usecs) static inline void timeval_sub_usecs(struct timeval *tv, long long usecs) { + i_assert(usecs >= 0); tv->tv_sec -= usecs / 1000000; tv->tv_usec -= (usecs % 1000000); if (tv->tv_usec < 0) {