From 66a8010ef7337aa734e430c40c690f4470384f62 Mon Sep 17 00:00:00 2001 From: Toni Date: Sun, 2 Oct 2022 12:48:24 +0200 Subject: Fix ndpi_timeval_to_milliseconds/microseconds for platforms with tv_usec is an unsigned int. (#1762) * implicit conversion to an 32 bit unsigned int leads to an overflow Signed-off-by: Toni Uhlig Signed-off-by: Toni Uhlig --- src/lib/ndpi_classify.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/ndpi_classify.c b/src/lib/ndpi_classify.c index e94bf2872..5c4fb2119 100644 --- a/src/lib/ndpi_classify.c +++ b/src/lib/ndpi_classify.c @@ -662,8 +662,9 @@ ndpi_timer_clear(pkt_timeval *a) u_int64_t ndpi_timeval_to_milliseconds(pkt_timeval ts) { - u_int64_t result = ts.tv_usec / 1000 + ts.tv_sec * 1000; - return result; + u_int64_t sec = ts.tv_sec; + u_int64_t usec = ts.tv_usec; + return usec / 1000 + sec * 1000; } /** @@ -674,8 +675,9 @@ ndpi_timeval_to_milliseconds(pkt_timeval ts) u_int64_t ndpi_timeval_to_microseconds(pkt_timeval ts) { - u_int64_t result = ts.tv_usec + ts.tv_sec * 1000 * 1000; - return result; + u_int64_t sec = ts.tv_sec; + u_int64_t usec = ts.tv_usec; + return usec + sec * 1000 * 1000;; } void -- cgit v1.2.3