diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-26 15:30:27 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-26 15:30:27 +0000 |
commit | 3dcdfcf884479107efb1c4007a592a1f086a4ce9 (patch) | |
tree | 17b974d3a11814d15f11033e7bf1fd4752583999 /thread.c | |
parent | bdc42b0ef3e92fb4a9467500a5af5fb662a35355 (diff) | |
download | ruby-3dcdfcf884479107efb1c4007a592a1f086a4ce9.tar.gz |
* 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.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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; } |