Navigation Menu

Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix issue 16797 - Zero clock resolution lead to division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-brannstrom committed Nov 27, 2016
1 parent dc622e5 commit 3a29ac5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/time.d
Expand Up @@ -2443,12 +2443,14 @@ extern(C) void _d_initMonoTime()
assert(0);

// For some reason, on some systems, clock_getres returns
// a resolution which is clearly wrong (it's a millisecond
// or worse, but the time is updated much more frequently
// than that). In such cases, we'll just use nanosecond
// resolution.
tps[i] = ts.tv_nsec >= 1000 ? 1_000_000_000L
: 1_000_000_000L / ts.tv_nsec;
// a resolution which is clearly wrong:
// - it's a millisecond or worse, but the time is updated
// much more frequently than that.
// - it's negative
// - it's zero
// In such cases, we'll just use nanosecond resolution.
tps[i] = ts.tv_sec != 0 || ts.tv_nsec <= 0 || ts.tv_nsec >= 1000
? 1_000_000_000L : 1_000_000_000L / ts.tv_nsec;
}
}
}
Expand Down

0 comments on commit 3a29ac5

Please sign in to comment.