1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2013-03-26 15:30:27 +00:00
parent bdc42b0ef3
commit 3dcdfcf884
3 changed files with 23 additions and 9 deletions

View file

@ -1,3 +1,9 @@
Wed Mar 27 00:28:45 2013 Tanaka Akira <akr@fsij.org>
* internal.h (TIMET_MAX_PLUS_ONE): Defined.
* thread.c (double2timeval): Saturate out-of-range values.
Tue Mar 26 23:41:18 2013 Tanaka Akira <akr@fsij.org>
* internal.h: Define TIMET_MAX and TIMET_MIN here.

View file

@ -22,6 +22,10 @@ extern "C" {
#define TIMET_MAX (~(time_t)0 <= 0 ? (time_t)((~(unsigned_time_t)0) >> 1) : (time_t)(~(unsigned_time_t)0))
#define TIMET_MIN (~(time_t)0 <= 0 ? (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) : (time_t)0)
#define TIMET_MAX_PLUS_ONE (~(time_t)0 <= 0 ? \
((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2 - 1)) : \
((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)) * (double)((time_t)1 << (sizeof(time_t) * CHAR_BIT / 2)))
struct rb_deprecated_classext_struct {
char conflict[sizeof(VALUE) * 3];
};

View file

@ -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 = 0;
return time;
time.tv_usec = 999999;
}
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 if (d <= TIMET_MIN) {
time.tv_sec = TIMET_MIN;
time.tv_usec = 0;
}
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;
}