aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-18 03:00:33 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-18 03:00:33 +0000
commit78cfcd63118c657c48ceb40b430fc1f3168909d5 (patch)
tree5d3330c522f479052350f6dff87e3742c47e66b8 /thread.c
parentcaea21e050184c2631180bf96cc816eb82cb97a6 (diff)
downloadruby-78cfcd63118c657c48ceb40b430fc1f3168909d5.tar.gz
thread.c (thread_join_m): handle negative timeouts correctly
Users may subtract and round into negative values when using Thread#join, so clamp the timeout to zero to avoid infinite/long timeouts. Note: other methods such as Kernel#sleep and IO.select will raise on negative values, but Thread#join is an outlier *shrug* This restores Ruby 2.5 (and earlier) behavior. Fixes: r62182 (commit c915390b9530c31b4665aacf27c1adfc114f768e) ("thread.c: avoid FP for Thread#join") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/thread.c b/thread.c
index 381163e008..e429808fc9 100644
--- a/thread.c
+++ b/thread.c
@@ -1061,6 +1061,8 @@ thread_join_m(int argc, VALUE *argv, VALUE self)
case T_NIL: break;
case T_FIXNUM:
timespec.tv_sec = NUM2TIMET(limit);
+ if (timespec.tv_sec < 0)
+ timespec.tv_sec = 0;
timespec.tv_nsec = 0;
ts = &timespec;
break;
@@ -1116,8 +1118,8 @@ double2timespec(struct timespec *ts, double d)
if (TIMESPEC_SEC_MAX_PLUS_ONE <= d) {
return NULL;
}
- else if (d <= TIMESPEC_SEC_MIN) {
- ts->tv_sec = TIMESPEC_SEC_MIN;
+ else if (d <= 0) {
+ ts->tv_sec = 0;
ts->tv_nsec = 0;
}
else {