mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: fix potential bug in String#split
* string.c (rb_str_split_m): fix potential bug when rb_memsearch() matches a octet in the middle of a multi-byte character sequence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c5da5b1ea2
commit
b3c70d4c7e
1 changed files with 6 additions and 3 deletions
9
string.c
9
string.c
|
@ -7469,7 +7469,8 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
else if (split_type == string) {
|
||||
char *ptr = RSTRING_PTR(str);
|
||||
char *temp = ptr;
|
||||
char *str_start = ptr;
|
||||
char *substr_start = ptr;
|
||||
char *eptr = RSTRING_END(str);
|
||||
char *sptr = RSTRING_PTR(spat);
|
||||
long slen = RSTRING_LEN(spat);
|
||||
|
@ -7484,11 +7485,13 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
ptr = t;
|
||||
continue;
|
||||
}
|
||||
rb_ary_push(result, rb_str_subseq(str, ptr - temp, end));
|
||||
rb_ary_push(result, rb_str_subseq(str, substr_start - str_start,
|
||||
(ptr+end) - substr_start));
|
||||
ptr += end + slen;
|
||||
substr_start = ptr;
|
||||
if (!NIL_P(limit) && lim <= ++i) break;
|
||||
}
|
||||
beg = ptr - temp;
|
||||
beg = ptr - str_start;
|
||||
}
|
||||
else {
|
||||
char *ptr = RSTRING_PTR(str);
|
||||
|
|
Loading…
Add table
Reference in a new issue