aboutsummaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-16 01:27:19 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-16 01:27:19 +0000
commited2e8b2e705c30fc4343d697daff9a08ff58502c (patch)
tree4ba9d0d7b7883467add1d347886e9617cbdffafd /time.c
parente51a55903e5b113e29fff2ccd2f696a09745b57c (diff)
downloadruby-ed2e8b2e705c30fc4343d697daff9a08ff58502c.tar.gz
time.c (time_timespec): fix tv_nsec overflow
test/ruby/test_float.rb (test_sleep_with_Float) causes tv_nsec to hit 1000000000 exactly. This bug is currently hidden from our test by the platform-dependent native_cond_timeout functions, but a future native_cond_timedwait implementation may prefer relative timeouts to match ConditionVariable#wait semantics more closely. [Bug #10144] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/time.c b/time.c
index 04f99f2dca..7ba83bbea7 100644
--- a/time.c
+++ b/time.c
@@ -2354,6 +2354,10 @@ time_timespec(VALUE num, int interval)
d = modf(RFLOAT_VALUE(num), &f);
if (d >= 0) {
t.tv_nsec = (int)(d*1e9+0.5);
+ if (t.tv_nsec >= 1000000000) {
+ t.tv_nsec -= 1000000000;
+ f += 1;
+ }
}
else if ((t.tv_nsec = (int)(-d*1e9+0.5)) > 0) {
t.tv_nsec = 1000000000 - t.tv_nsec;