* time.c (rb_localtime_r2): fix localtime overflow check.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-06-10 15:45:34 +00:00
Родитель 42eca4f46e
Коммит cb962c5ae5
2 изменённых файлов: 9 добавлений и 3 удалений

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

@ -1,3 +1,7 @@
Fri Jun 11 00:42:45 2010 Tanaka Akira <akr@fsij.org>
* time.c (rb_localtime_r2): fix localtime overflow check.
Thu Jun 10 23:05:44 2010 Tanaka Akira <akr@fsij.org>
* time.c (rb_localtime_r2): refine localtime overflow check for

8
time.c
Просмотреть файл

@ -872,12 +872,13 @@ rb_localtime_r2(const time_t *t, struct tm *result)
if (result) {
int gmtoff1 = 0;
int gmtoff2 = 0;
struct tm tmp = *result;
# if defined(HAVE_STRUCT_TM_TM_GMTOFF)
gmtoff1 = result->tm_gmtoff;
# endif
time_t t2 = mktime(result);
time_t t2 = mktime(&tmp);
# if defined(HAVE_STRUCT_TM_TM_GMTOFF)
gmtoff2 = result->tm_gmtoff;
gmtoff2 = tmp.tm_gmtoff;
# endif
if (*t + gmtoff1 != t2 + gmtoff2)
result = NULL;
@ -894,7 +895,8 @@ rb_localtime_r2(const time_t *t, struct tm *result)
result = rb_gmtime_r(t, result);
#if defined(HAVE_TIMEGM) && defined(LOCALTIME_OVERFLOW_PROBLEM)
if (result) {
time_t t2 = timegm(result);
struct tm tmp = *result;
time_t t2 = timegm(&tmp);
if (*t != t2)
result = NULL;
}