diff options
author | nagachika <nagachika@ruby-lang.org> | 2021-03-20 16:16:45 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-03-20 16:16:45 +0900 |
commit | 364c8595884808315aaec9605bf2423963ed81c0 (patch) | |
tree | 9d1f97e3ebdbb864d11767a7fd25b976fb0fba37 | |
parent | ec779aa56f4d6df465e721818d73d0d48fdf03f2 (diff) |
merge revision(s) a85ed626f18d1014d09fb37eb0a703976c3d2b53: [Backport #17731]
Fix Enumerable#inject with high negative fixnums [Bug #17731]
---
enum.c | 2 +-
test/ruby/test_enum.rb | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
-rw-r--r-- | enum.c | 2 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 2 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 4 insertions, 2 deletions
@@ -771,7 +771,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) if (FIXNUM_P(e)) { n += FIX2LONG(e); /* should not overflow long type */ if (!FIXABLE(n)) { - v = rb_big_plus(ULONG2NUM(n), v); + v = rb_big_plus(LONG2NUM(n), v); n = 0; } } diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 7b647231c8..ebb7e78381 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -228,11 +228,13 @@ class TestEnumerable < Test::Unit::TestCase assert_equal(15, [3, 5, 7].inject(:+)) assert_float_equal(15.0, [3, 5, 7.0].inject(:+)) assert_equal(2*FIXNUM_MAX, Array.new(2, FIXNUM_MAX).inject(:+)) + assert_equal(3*FIXNUM_MAX, Array.new(3, FIXNUM_MAX).inject(:+)) assert_equal(2*(FIXNUM_MAX+1), Array.new(2, FIXNUM_MAX+1).inject(:+)) assert_equal(10*FIXNUM_MAX, Array.new(10, FIXNUM_MAX).inject(:+)) assert_equal(0, ([FIXNUM_MAX, 1, -FIXNUM_MAX, -1]*10).inject(:+)) assert_equal(FIXNUM_MAX*10, ([FIXNUM_MAX+1, -1]*10).inject(:+)) assert_equal(2*FIXNUM_MIN, Array.new(2, FIXNUM_MIN).inject(:+)) + assert_equal(3*FIXNUM_MIN, Array.new(3, FIXNUM_MIN).inject(:+)) assert_equal((FIXNUM_MAX+1).to_f, [FIXNUM_MAX, 1, 0.0].inject(:+)) assert_float_equal(10.0, [3.0, 5].inject(2.0, :+)) assert_float_equal((FIXNUM_MAX+1).to_f, [0.0, FIXNUM_MAX+1].inject(:+)) @@ -2,7 +2,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 177 +#define RUBY_PATCHLEVEL 178 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 3 |