From 6cedcf890aa88879bb5a7f84a4d83cc8ac2a7268 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 10 Jun 2010 14:10:25 +0000 Subject: [PATCH] * time.c (rb_localtime_r2): refine localtime overflow check for FreeBSD 6.4. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_time_tz.rb | 6 ++++-- time.c | 14 +++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd9edfcc64..35a74de20b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 10 23:05:44 2010 Tanaka Akira + + * time.c (rb_localtime_r2): refine localtime overflow check for + FreeBSD 6.4. + Thu Jun 10 21:35:27 2010 Tanaka Akira * time.c (find_time_t): always outerpolate from past. diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index ea7b51d5d2..4e781cd820 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -153,8 +153,10 @@ class TestTimeTZ < Test::Unit::TestCase sample.each {|tz, u, l, gmtoff| with_tz(tz) { expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)]) - t = Time.utc(*u).localtime - assert_equal(expected, time_to_s(t), "TZ=#{tz} Time.utc(#{u.map(&:inspect).join(', ')}).localtime") + mesg = "TZ=#{tz} Time.utc(#{u.map(&:inspect).join(', ')}).localtime" + t = nil + assert_nothing_raised(mesg) { t = Time.utc(*u).localtime } + assert_equal(expected, time_to_s(t), mesg) assert_equal(gmtoff, t.gmtoff) } } diff --git a/time.c b/time.c index 890b0c9a11..13938b944a 100644 --- a/time.c +++ b/time.c @@ -870,9 +870,17 @@ rb_localtime_r2(const time_t *t, struct tm *result) result = rb_localtime_r(t, result); #if defined(HAVE_MKTIME) && defined(LOCALTIME_OVERFLOW_PROBLEM) if (result) { - time_t t2 = mktime(result); - if (*t != t2) - result = NULL; + int gmtoff1 = 0; + int gmtoff2 = 0; +# if defined(HAVE_STRUCT_TM_TM_GMTOFF) + gmtoff1 = result->tm_gmtoff; +# endif + time_t t2 = mktime(result); +# if defined(HAVE_STRUCT_TM_TM_GMTOFF) + gmtoff2 = result->tm_gmtoff; +# endif + if (*t + gmtoff1 != t2 + gmtoff2) + result = NULL; } #endif return result;