diff options
author | Peter Zhu <peter@peterzhu.ca> | 2020-09-28 17:35:27 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-09-30 00:31:59 +0900 |
commit | f7bd9f075030e5fa876320c1624a80685a636e82 (patch) | |
tree | c51fdea056b14938e1dc73fd93c3fd99400c090c | |
parent | cece71b46708d69c74583d48478ea4d0401bb746 (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.c | 2 | ||||
-rw-r--r-- | test/ruby/test_integer.rb | 1 |
2 files changed, 2 insertions, 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; } 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 |