aboutsummaryrefslogtreecommitdiffstats
path: root/src/system
diff options
context:
space:
mode:
authorPHO <pho@cielonegro.org>2015-01-26 14:54:16 +0900
committerMax Kellermann <max@duempel.org>2015-01-29 08:33:48 +0100
commita4f4fc50b9e1c825806dc7dc44ac8eb4398a3a5b (patch)
treed8abfdb8c81c2c6428e33cb6c71ecebf247c0266 /src/system
parentad1b6ef0ac5e7c869b6adbede153e8b2ac55d708 (diff)
downloadmpd-a4f4fc50b9e1c825806dc7dc44ac8eb4398a3a5b.tar.gz
mpd-a4f4fc50b9e1c825806dc7dc44ac8eb4398a3a5b.tar.xz
mpd-a4f4fc50b9e1c825806dc7dc44ac8eb4398a3a5b.zip
Avoid integer overflow in MonotonicClock{S,MS,US}
This is Darwin specific: the previous implementation was causing an integer overflow when base.numer is very large. On PPC Darwin, the timebase info is 1000000000/33330116 and this is too large for integer arithmetic.
Diffstat (limited to '')
-rw-r--r--src/system/Clock.cxx8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx
index 347997a44..916bda56c 100644
--- a/src/system/Clock.cxx
+++ b/src/system/Clock.cxx
@@ -40,8 +40,8 @@ MonotonicClockMS(void)
if (base.denom == 0)
(void)mach_timebase_info(&base);
- return (unsigned)((mach_absolute_time() * base.numer)
- / (1000000 * base.denom));
+ return (unsigned)(((double)mach_absolute_time() * base.numer)
+ / base.denom / 1000000);
#elif defined(CLOCK_MONOTONIC)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -82,8 +82,8 @@ MonotonicClockUS(void)
if (base.denom == 0)
(void)mach_timebase_info(&base);
- return ((uint64_t)mach_absolute_time() * (uint64_t)base.numer)
- / (1000 * (uint64_t)base.denom);
+ return (uint64_t)(((double)mach_absolute_time() * base.numer)
+ / base.denom / 1000);
#elif defined(CLOCK_MONOTONIC)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);