mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: check before modify
* string.c (rb_str_setbyte): check the argument first not to discard shared string and code range unnecessarily until actually changing the contents. pointed out by headius. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
34c83a37c2
commit
8c0b2a2860
2 changed files with 11 additions and 4 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Apr 4 11:30:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_setbyte): check the argument first not to
|
||||
discard shared string and code range unnecessarily until
|
||||
actually changing the contents. pointed out by headius.
|
||||
|
||||
Sat Apr 4 08:16:43 2015 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* lib/net/http.rb (edit_path): use path which is absolute ftp url
|
||||
|
|
9
string.c
9
string.c
|
@ -4567,13 +4567,14 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
|
|||
{
|
||||
long pos = NUM2LONG(index);
|
||||
int byte = NUM2INT(value);
|
||||
long len = RSTRING_LEN(str);
|
||||
|
||||
rb_str_modify(str);
|
||||
|
||||
if (pos < -RSTRING_LEN(str) || RSTRING_LEN(str) <= pos)
|
||||
if (pos < -len || len <= pos)
|
||||
rb_raise(rb_eIndexError, "index %ld out of string", pos);
|
||||
if (pos < 0)
|
||||
pos += RSTRING_LEN(str);
|
||||
pos += len;
|
||||
|
||||
rb_str_modify(str);
|
||||
|
||||
RSTRING_PTR(str)[pos] = byte;
|
||||
|
||||
|
|
Loading…
Reference in a new issue