From 0d0d39e01584814774289292b61a71cd986885ac Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 21 Nov 2008 18:40:00 +0000 Subject: Avoid a potential 32-bit overflow in Timer::combine_timers by promoting to 64 bit values before doing multiplication. --- src/timer/timer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/timer/timer.cpp') diff --git a/src/timer/timer.cpp b/src/timer/timer.cpp index 7ea4f56ad..8758aad21 100644 --- a/src/timer/timer.cpp +++ b/src/timer/timer.cpp @@ -42,8 +42,10 @@ u32bit Timer::slow_poll(byte out[], u32bit length) u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) { static const u64bit NANOSECONDS_UNITS = 1000000000; - parts *= (NANOSECONDS_UNITS / parts_hz); - return ((seconds * NANOSECONDS_UNITS) + parts); + + u64bit res = seconds * NANOSECONDS_UNITS; + res += parts * (NANOSECONDS_UNITS / parts_hz); + return res; } /** -- cgit v1.2.3