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
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/3a29ac5293dfa5e85790480b838eaa45f59c14a8 fix issue 16797 - Zero clock resolution lead to division by zero https://github.com/dlang/druntime/commit/09d570f47cd1c727298e4b0fe1ad668f1dd28e4e Merge pull request #1702 from joakim-brannstrom/fix16797 fix issue 16797 - Zero clock resolution lead to division by zero
Comment #2 by github-bugzilla — 2016-12-27T13:11:09Z
Commits pushed to scope at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/3a29ac5293dfa5e85790480b838eaa45f59c14a8 fix issue 16797 - Zero clock resolution lead to division by zero https://github.com/dlang/druntime/commit/09d570f47cd1c727298e4b0fe1ad668f1dd28e4e Merge pull request #1702 from joakim-brannstrom/fix16797
Comment #3 by github-bugzilla — 2017-01-07T03:02:08Z
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/3a29ac5293dfa5e85790480b838eaa45f59c14a8 fix issue 16797 - Zero clock resolution lead to division by zero https://github.com/dlang/druntime/commit/09d570f47cd1c727298e4b0fe1ad668f1dd28e4e Merge pull request #1702 from joakim-brannstrom/fix16797
Comment #4 by github-bugzilla — 2017-01-16T23:24:36Z
Commits pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/3a29ac5293dfa5e85790480b838eaa45f59c14a8 fix issue 16797 - Zero clock resolution lead to division by zero https://github.com/dlang/druntime/commit/09d570f47cd1c727298e4b0fe1ad668f1dd28e4e Merge pull request #1702 from joakim-brannstrom/fix16797