ruby-changes:65502
From: nagachika <ko1@a...>
Date: Sat, 20 Mar 2021 16:30:36 +0900 (JST)
Subject: [ruby-changes:65502] 364c859588 (ruby_2_7): merge revision(s) a85ed626f18d1014d09fb37eb0a703976c3d2b53: [Backport #17731]
https://git.ruby-lang.org/ruby.git/commit/?id=364c859588 From 364c8595884808315aaec9605bf2423963ed81c0 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sat, 20 Mar 2021 16:16:45 +0900 Subject: 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(-) --- enum.c | 2 +- test/ruby/test_enum.rb | 2 ++ version.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/enum.c b/enum.c index cc77964..fb0ced5 100644 --- a/enum.c +++ b/enum.c @@ -771,7 +771,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) https://github.com/ruby/ruby/blob/trunk/enum.c#L771 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 7b64723..ebb7e78 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -228,11 +228,13 @@ class TestEnumerable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L228 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(:+)) diff --git a/version.h b/version.h index 538cd8a..4c36f47 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2 # 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/