From 5e4ab77f33a8c40047c734e19fa5cfab30057d6f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 19 Dec 2015 23:25:27 -0500 Subject: [PATCH] Fix overflow issues with thread-sleep! --- runtime.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime.c b/runtime.c index 0606400a..57e9aa96 100644 --- a/runtime.c +++ b/runtime.c @@ -3211,11 +3211,12 @@ void Cyc_end_thread(gc_thread_data *thd) // For now, accept a number of milliseconds to sleep object Cyc_thread_sleep(void *data, object timeout) { - // TODO: looks like there are overflow issues here: struct timespec tim; + long value; Cyc_check_num(data, timeout); - tim.tv_sec = 0; - tim.tv_nsec = ((integer_type *)timeout)->value * NANOSECONDS_PER_MILLISECOND; + value = ((integer_type *)timeout)->value; + tim.tv_sec = value / 1000; + tim.tv_nsec = (value % 1000) * NANOSECONDS_PER_MILLISECOND; nanosleep(&tim, NULL); return boolean_t; }