* 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
Родитель bdc42b0ef3
Коммит 3dcdfcf884
3 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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];
};

Просмотреть файл

@ -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;
}