[前][次][番号順一覧][スレッド一覧]

ruby-changes:33371

From: nobu <ko1@a...>
Date: Thu, 27 Mar 2014 18:47:06 +0900 (JST)
Subject: [ruby-changes:33371] nobu:r45450 (trunk): string.c: mustnot_broken

nobu	2014-03-27 18:47:03 +0900 (Thu, 27 Mar 2014)

  New Revision: 45450

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45450

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

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 45449)
+++ string.c	(revision 45450)
@@ -157,6 +157,14 @@ get_encoding(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L157
     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, VA https://github.com/ruby/ruby/blob/trunk/string.c#L6215
 	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) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]