Bug 16797 – Zero clock resolution lead to division by zero
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-11-26T20:01:00Z
Last change time
2017-01-16T23:24:36Z
Assigned to
nobody
Creator
wikodes
Comments
Comment #0 by wikodes — 2016-11-26T20:01:24Z
Some linux systems (eg. CentOS 6.4/7) return a clock result of zero.
Data gathered with:
#include <time.h>
#include <stdio.h>
int main() {
struct timespec ts;
int res;
int i;
for (i = 0; i < 10; ++i) {
res = clock_getres(i, &ts);
printf("i %d tv_sec %ld tv_nsec %ld\n", i, ts.tv_sec, ts.tv_nsec);
}
}
output:
...
i 4 tv_sec 0 tv_nsec 0
This lead to a division by zero in druntime/src/core/time.d:_d_initMonoTime
... (around line 2450)
tps[i] = ts.tv_nsec >= 1000 ? 1_000_000_000L : 1_000_000_000L / ts.tv_nsec;
Comment #1 by github-bugzilla — 2016-11-27T05:55:36Z