From 227a5a2aae81d9933afb90aa3e77a84b7a768b02 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 27 Mar 2014 09:47:03 +0000 Subject: [PATCH] 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 --- string.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/string.c b/string.c index c7150a8c3e..77930c1b45 100644 --- a/string.c +++ b/string.c @@ -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) {