mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix unsigned int overflow in error message for chr
The error message has an integer overflow because it treats an unsigned int as a signed int. Before: ``` > 3_000_000_000.chr -1294967296 out of char range (RangeError) ``` After: ``` > 3_000_000_000.chr 3000000000 out of char range (RangeError) ``` Redmine ticket: https://bugs.ruby-lang.org/issues/17186
This commit is contained in:
parent
cece71b467
commit
f7bd9f0750
Notes:
git
2020-09-30 00:32:35 +09:00
2 changed files with 2 additions and 1 deletions
|
@ -3417,7 +3417,7 @@ int_chr(int argc, VALUE *argv, VALUE num)
|
|||
if (0xff < i) {
|
||||
enc = rb_default_internal_encoding();
|
||||
if (!enc) {
|
||||
rb_raise(rb_eRangeError, "%d out of char range", i);
|
||||
rb_raise(rb_eRangeError, "%u out of char range", i);
|
||||
}
|
||||
goto decode;
|
||||
}
|
||||
|
|
|
@ -260,6 +260,7 @@ class TestInteger < Test::Unit::TestCase
|
|||
assert_equal("a", "a".ord.chr)
|
||||
assert_raise(RangeError) { (-1).chr }
|
||||
assert_raise(RangeError) { 0x100.chr }
|
||||
assert_raise_with_message(RangeError, "3000000000 out of char range") { 3_000_000_000.chr }
|
||||
end
|
||||
|
||||
def test_upto
|
||||
|
|
Loading…
Reference in a new issue