date_core.c: defensive code

* ext/date/date_core.c (f_cmp): check comparison failure.

* ext/date/date_core.c (d_lite_step): deal with the comparison
  result more defensively.  [ruby-core:85796] [Bug #14549]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-25 04:28:11 +00:00
parent e110c0ddc5
commit d3d845396e
2 changed files with 27 additions and 16 deletions

View file

@ -262,4 +262,17 @@ class TestDateArith < Test::Unit::TestCase
assert_equal(8, e.to_a.size)
end
def test_step__compare
o = Object.new
def o.<=>(*);end
assert_raise(ArgumentError) {
Date.new(2000, 1, 1).step(3, o).to_a
}
o = Object.new
def o.<=>(*);2;end
a = []
Date.new(2000, 1, 1).step(3, o) {|d| a << d}
assert_empty(a)
end
end