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.
This commit is contained in:
parent
7bf638b0de
commit
39abd3ecb4
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
|||||||
ver 0.19.9 (not yet released)
|
ver 0.19.9 (not yet released)
|
||||||
* decoder
|
* decoder
|
||||||
- dsdiff, dsf: raise ID3 tag limit to 1 MB
|
- dsdiff, dsf: raise ID3 tag limit to 1 MB
|
||||||
|
* fix clock integer overflow on OS X
|
||||||
* fix build failure with uClibc
|
* fix build failure with uClibc
|
||||||
* fix build failure on non-POSIX operating systems
|
* fix build failure on non-POSIX operating systems
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ MonotonicClockS(void)
|
|||||||
if (base.denom == 0)
|
if (base.denom == 0)
|
||||||
(void)mach_timebase_info(&base);
|
(void)mach_timebase_info(&base);
|
||||||
|
|
||||||
return (unsigned)((mach_absolute_time() * base.numer / 1000)
|
return (unsigned)(((double)mach_absolute_time() * base.numer / 1000)
|
||||||
/ (1000000 * base.denom));
|
/ base.denom / 1000000);
|
||||||
#elif defined(CLOCK_MONOTONIC)
|
#elif defined(CLOCK_MONOTONIC)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
@ -62,8 +62,8 @@ MonotonicClockMS(void)
|
|||||||
if (base.denom == 0)
|
if (base.denom == 0)
|
||||||
(void)mach_timebase_info(&base);
|
(void)mach_timebase_info(&base);
|
||||||
|
|
||||||
return (unsigned)((mach_absolute_time() * base.numer)
|
return (unsigned)(((double)mach_absolute_time() * base.numer)
|
||||||
/ (1000000 * base.denom));
|
/ base.denom / 1000000);
|
||||||
#elif defined(CLOCK_MONOTONIC)
|
#elif defined(CLOCK_MONOTONIC)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
@ -104,8 +104,8 @@ MonotonicClockUS(void)
|
|||||||
if (base.denom == 0)
|
if (base.denom == 0)
|
||||||
(void)mach_timebase_info(&base);
|
(void)mach_timebase_info(&base);
|
||||||
|
|
||||||
return ((uint64_t)mach_absolute_time() * (uint64_t)base.numer)
|
return (uint64_t)(((double)mach_absolute_time() * base.numer)
|
||||||
/ (1000 * (uint64_t)base.denom);
|
/ base.denom / 1000);
|
||||||
#elif defined(CLOCK_MONOTONIC)
|
#elif defined(CLOCK_MONOTONIC)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
Loading…
Reference in New Issue
Block a user