aboutsummaryrefslogtreecommitdiffstats
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:34:37 +0100
commit39abd3ecb493c2a12dd08a31042dce07664642d2 (patch)
treeb3517eddb3a7414275c924a52eb6b2b1c525d5fe
parent7bf638b0deedf02aea46e72f6f3c848e86f2ce0d (diff)
downloadmpd-39abd3ecb493c2a12dd08a31042dce07664642d2.tar.gz
mpd-39abd3ecb493c2a12dd08a31042dce07664642d2.tar.xz
mpd-39abd3ecb493c2a12dd08a31042dce07664642d2.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.
-rw-r--r--NEWS1
-rw-r--r--src/system/Clock.cxx12
2 files changed, 7 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index ed6f0912e..ac9caacb1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
ver 0.19.9 (not yet released)
* decoder
- dsdiff, dsf: raise ID3 tag limit to 1 MB
+* fix clock integer overflow on OS X
* fix build failure with uClibc
* fix build failure on non-POSIX operating systems
diff --git a/src/system/Clock.cxx b/src/system/Clock.cxx
index 9baa0c0ca..c2f5e5087 100644
--- a/src/system/Clock.cxx
+++ b/src/system/Clock.cxx
@@ -40,8 +40,8 @@ MonotonicClockS(void)
if (base.denom == 0)
(void)mach_timebase_info(&base);
- return (unsigned)((mach_absolute_time() * base.numer / 1000)
- / (1000000 * base.denom));
+ return (unsigned)(((double)mach_absolute_time() * base.numer / 1000)
+ / base.denom / 1000000);
#elif defined(CLOCK_MONOTONIC)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -62,8 +62,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);
@@ -104,8 +104,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);