* time.c (search_time_t): limit guess range by mktime if it is

availabe.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-03-30 11:31:44 +00:00
Родитель 7c34ed846f
Коммит 7bb7e17675
3 изменённых файлов: 24 добавлений и 0 удалений

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

@ -1,3 +1,8 @@
Tue Mar 30 20:25:34 2004 Tanaka Akira <akr@m17n.org>
* time.c (search_time_t): limit guess range by mktime if it is
availabe.
Tue Mar 30 18:19:00 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Mar 30 18:19:00 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_eval): fix SEGV at retry in iterator's receiver. * eval.c (rb_eval): fix SEGV at retry in iterator's receiver.

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

@ -23,4 +23,14 @@ class TestTime < Test::Unit::TestCase
assert_equal(Time.utc(2000, 3, 21, 0, 30) \ assert_equal(Time.utc(2000, 3, 21, 0, 30) \
-Time.utc(2000, 3, 21, 3, 30), -3*3600) -Time.utc(2000, 3, 21, 3, 30), -3*3600)
end end
def test_negative
begin
Time.at(-1)
rescue ArgumentError
return
end
assert_equal(-1, Time.utc(1969, 12, 31, 23, 59, 59).tv_sec)
assert_equal(-2, Time.utc(1969, 12, 31, 23, 59, 58).tv_sec)
end
end end

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

@ -444,6 +444,15 @@ search_time_t(tptr, utc_p)
(1UL << (8 * sizeof(time_t) - 1)) - 1 : (1UL << (8 * sizeof(time_t) - 1)) - 1 :
~(time_t)0; ~(time_t)0;
#if defined(HAVE_MKTIME)
if ((guess = mktime(tptr)) != -1) {
if (guess_lo < guess - 24 * 60 * 60)
guess_lo = guess - 24 * 60 * 60;
if (guess + 24 * 60 * 60 < guess_hi)
guess_hi = guess + 24 * 60 * 60;
}
#endif
tm = (utc_p ? gmtime : localtime)(&guess_lo); tm = (utc_p ? gmtime : localtime)(&guess_lo);
if (!tm) goto error; if (!tm) goto error;
d = tmcmp(tptr, tm); d = tmcmp(tptr, tm);