ruby-changes:45970
From: nobu <ko1@a...>
Date: Tue, 21 Mar 2017 12:16:03 +0900 (JST)
Subject: [ruby-changes:45970] nobu:r58041 (trunk): stringio.c: check range
nobu 2017-03-21 12:15:57 +0900 (Tue, 21 Mar 2017) New Revision: 58041 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58041 Log: stringio.c: check range * ext/stringio/stringio.c (strio_ungetc): raise RangeError instead of TypeError at too big value, as well as IO#ungetc. Modified files: trunk/ext/stringio/stringio.c trunk/test/stringio/test_stringio.rb Index: ext/stringio/stringio.c =================================================================== --- ext/stringio/stringio.c (revision 58040) +++ ext/stringio/stringio.c (revision 58041) @@ -766,8 +766,8 @@ strio_ungetc(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L766 check_modifiable(ptr); if (NIL_P(c)) return Qnil; - if (FIXNUM_P(c)) { - int len, cc = FIX2INT(c); + if (RB_INTEGER_TYPE_P(c)) { + int len, cc = NUM2INT(c); char buf[16]; enc = rb_enc_get(ptr->string); Index: test/stringio/test_stringio.rb =================================================================== --- test/stringio/test_stringio.rb (revision 58040) +++ test/stringio/test_stringio.rb (revision 58041) @@ -455,6 +455,7 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L455 assert_equal("2", f.getc) assert_raise(RangeError) {f.ungetc(0x1ffffff)} + assert_raise(RangeError) {f.ungetc(0xffffffffffffff)} ensure f.close unless f.closed? end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/