mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[ruby/date] [Bug #21436] check for fixnum lower bound in m_ajd
Issue - https://bugs.ruby-lang.org/issues/21436
Apparently, the lower bound check is missing, which results in overflow & wrapping later on in RB_INT2FIX
Signed-off-by: Dmitry Dygalo <dmitry.dygalo@workato.com>
67d75e8423
This commit is contained in:
parent
c1877d431e
commit
022c18b60d
2 changed files with 6 additions and 1 deletions
|
@ -1599,7 +1599,7 @@ m_ajd(union DateData *x)
|
|||
|
||||
if (simple_dat_p(x)) {
|
||||
r = m_real_jd(x);
|
||||
if (FIXNUM_P(r) && FIX2LONG(r) <= (FIXNUM_MAX / 2)) {
|
||||
if (FIXNUM_P(r) && FIX2LONG(r) <= (FIXNUM_MAX / 2) && FIX2LONG(r) >= (FIXNUM_MIN + 1) / 2) {
|
||||
long ir = FIX2LONG(r);
|
||||
ir = ir * 2 - 1;
|
||||
return rb_rational_new2(LONG2FIX(ir), INT2FIX(2));
|
||||
|
|
|
@ -97,6 +97,11 @@ class TestSH < Test::Unit::TestCase
|
|||
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
|
||||
end
|
||||
|
||||
def test_ajd
|
||||
assert_equal(Date.civil(2008, 1, 16).ajd, 4908963r/2)
|
||||
assert_equal(Date.civil(-11082381539297990, 2, 19).ajd, -8095679714453739481r/2)
|
||||
end
|
||||
|
||||
def test_ordinal
|
||||
d = Date.ordinal
|
||||
assert_equal([-4712, 1], [d.year, d.yday])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue