summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-26 15:30:27 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-26 15:30:27 +0000
commit3dcdfcf884479107efb1c4007a592a1f086a4ce9 (patch)
tree17b974d3a11814d15f11033e7bf1fd4752583999 /thread.c
parentbdc42b0ef3e92fb4a9467500a5af5fb662a35355 (diff)
* internal.h (TIMET_MAX_PLUS_ONE): Defined.
* thread.c (double2timeval): Saturate out-of-range values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/thread.c b/thread.c
index 9c149928d0..c510b93e9a 100644
--- a/thread.c
+++ b/thread.c
@@ -916,17 +916,21 @@ double2timeval(double d)
{
struct timeval time;
- if (isinf(d)) {
+ if (TIMET_MAX_PLUS_ONE <= d) {
time.tv_sec = TIMET_MAX;
+ time.tv_usec = 999999;
+ }
+ else if (d <= TIMET_MIN) {
+ time.tv_sec = TIMET_MIN;
time.tv_usec = 0;
- return time;
}
-
- time.tv_sec = (int)d;
- time.tv_usec = (int)((d - (int)d) * 1e6);
- if (time.tv_usec < 0) {
- time.tv_usec += (int)1e6;
- time.tv_sec -= 1;
+ else {
+ time.tv_sec = (time_t)d;
+ time.tv_usec = (int)((d - (time_t)d) * 1e6);
+ if (time.tv_usec < 0) {
+ time.tv_usec += (int)1e6;
+ time.tv_sec -= 1;
+ }
}
return time;
}