diff options
author | lloyd <[email protected]> | 2008-11-21 18:40:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-21 18:40:00 +0000 |
commit | 0d0d39e01584814774289292b61a71cd986885ac (patch) | |
tree | 0e3be143facb7c3905844fdfaad0d3ffe5413e24 /src | |
parent | 7d37817a7ee9a697a1f748231f23ef185c8b1d75 (diff) |
Avoid a potential 32-bit overflow in Timer::combine_timers by promoting
to 64 bit values before doing multiplication.
Diffstat (limited to 'src')
-rw-r--r-- | src/timer/timer.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
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; } /** |