1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

string.c: mustnot_broken

* string.c (mustnot_broken): extract function to reject invalid
  byte sequence, from rb_str_split_m().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-03-27 09:47:03 +00:00
parent ffdb3ce9b9
commit 227a5a2aae

View file

@ -157,6 +157,14 @@ get_encoding(VALUE str)
return get_actual_encoding(ENCODING_GET(str), str);
}
static void
mustnot_broken(VALUE str)
{
if (is_broken_string(str)) {
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(STR_ENC_GET(str)));
}
}
static int fstring_cmp(VALUE a, VALUE b);
static st_table* frozen_strings;
@ -6207,12 +6215,8 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
char *sptr = RSTRING_PTR(spat);
long slen = RSTRING_LEN(spat);
if (is_broken_string(str)) {
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(STR_ENC_GET(str)));
}
if (is_broken_string(spat)) {
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(STR_ENC_GET(spat)));
}
mustnot_broken(str);
mustnot_broken(spat);
enc = rb_enc_check(str, spat);
while (ptr < eptr &&
(end = rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) {