ruby-changes:63384
From: Kenta <ko1@a...>
Date: Tue, 20 Oct 2020 16:02:51 +0900 (JST)
Subject: [ruby-changes:63384] 18cecda46e (master): range.c: Fix an exception message in rb_range_beg_len
https://git.ruby-lang.org/ruby.git/commit/?id=18cecda46e From 18cecda46e427362fa3447679e5d8a917b5d6cb6 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> Date: Tue, 20 Oct 2020 16:00:35 +0900 Subject: range.c: Fix an exception message in rb_range_beg_len [Bug #17271] diff --git a/range.c b/range.c index 17d2992..c019fcf 100644 --- a/range.c +++ b/range.c @@ -1332,7 +1332,7 @@ rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp) https://github.com/ruby/ruby/blob/trunk/range.c#L1332 VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) { - long beg, end, origbeg, origend; + long beg, end; VALUE b, e; int excl; @@ -1341,8 +1341,6 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) https://github.com/ruby/ruby/blob/trunk/range.c#L1341 beg = NIL_P(b) ? 0 : NUM2LONG(b); end = NIL_P(e) ? -1 : NUM2LONG(e); if (NIL_P(e)) excl = 0; - origbeg = beg; - origend = end; if (beg < 0) { beg += len; if (beg < 0) @@ -1368,8 +1366,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) https://github.com/ruby/ruby/blob/trunk/range.c#L1366 out_of_range: if (err) { - rb_raise(rb_eRangeError, "%ld..%s%ld out of range", - origbeg, excl ? "." : "", origend); + rb_raise(rb_eRangeError, "%+"PRIsVALUE" out of range", range); } return Qnil; } diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 5d17852..bc5d863 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2381,6 +2381,9 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2381 assert_raise(ArgumentError) { [0].freeze[0, 0, 0] = 0 } assert_raise(TypeError) { [0][:foo] = 0 } assert_raise(FrozenError) { [0].freeze[:foo] = 0 } + + # [Bug #17271] + assert_raise_with_message(RangeError, "-7.. out of range") { [*0..5][-7..] = 1 } end def test_first2 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/