mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) a85ed626f1
: [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(-)
This commit is contained in:
parent
ec779aa56f
commit
364c859588
3 changed files with 4 additions and 2 deletions
2
enum.c
2
enum.c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue