summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2020-09-28 17:35:27 -0400
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-09-30 00:31:59 +0900
commitf7bd9f075030e5fa876320c1624a80685a636e82 (patch)
treec51fdea056b14938e1dc73fd93c3fd99400c090c
parentcece71b46708d69c74583d48478ea4d0401bb746 (diff)
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
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3602
-rw-r--r--numeric.c2
-rw-r--r--test/ruby/test_integer.rb1
2 files changed, 2 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 387e46f29b..6d4eb86b1a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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;
}
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index a111698771..2755987276 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -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