diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-17 21:36:17 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-17 21:36:17 +0000 |
commit | 4cb618e7aacf84cf7c241ee0513bbb37e1068c9d (patch) | |
tree | 9022b6c440e8dcaf11d9f0eb04125ef84fb58677 /string.c | |
parent | b3b786c580995b31dcc0259890cefdb1385998c6 (diff) |
merge revision(s) 66760,66761,66824: [Backport #15460]
Follow behaviour of IO#ungetbyte
see r65802 and [Bug #14359]
* expand tabs.
setbyte / ungetbyte allow out-of-range integers
* string.c: String#setbyte to accept arbitrary integers [Bug #15460]
* io.c: ditto for IO#ungetbyte
* ext/strringio/stringio.c: ditto for StringIO#ungetbyte
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -5411,7 +5411,6 @@ static VALUE rb_str_setbyte(VALUE str, VALUE index, VALUE value) { long pos = NUM2LONG(index); - int byte = NUM2INT(value); long len = RSTRING_LEN(str); char *head, *left = 0; unsigned char *ptr; @@ -5422,10 +5421,10 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value) rb_raise(rb_eIndexError, "index %ld out of string", pos); if (pos < 0) pos += len; - if (byte < 0) - rb_raise(rb_eRangeError, "integer %d too small to convert into `unsigned char'", byte); - if (UCHAR_MAX < byte) - rb_raise(rb_eRangeError, "integer %d too big to convert into `unsigned char'", byte); + + VALUE v = rb_to_int(value); + VALUE w = rb_int_modulo(v, INT2FIX(256)); + unsigned char byte = NUM2INT(w) & 0xFF; if (!str_independent(str)) str_make_independent(str); |