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

ruby-changes:2700

From: ko1@a...
Date: 11 Dec 2007 13:58:15 +0900
Subject: [ruby-changes:2700] nobu - Ruby:r14191 (trunk): * transcode.c (transcode_loop): get rid of SEGV at sequence can not be

nobu	2007-12-11 13:57:51 +0900 (Tue, 11 Dec 2007)

  New Revision: 14191

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c

  Log:
    * transcode.c (transcode_loop): get rid of SEGV at sequence can not be
      converted.
    
    * transcode.c (rb_str_transcode_bang): copy encoding.  [ruby-dev:32532]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14191&r2=14190
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/transcode.c?r1=14191&r2=14190

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14190)
+++ ChangeLog	(revision 14191)
@@ -1,3 +1,10 @@
+Tue Dec 11 13:57:25 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* transcode.c (transcode_loop): get rid of SEGV at sequence can not be
+	  converted.
+
+	* transcode.c (rb_str_transcode_bang): copy encoding.  [ruby-dev:32532]
+
 Tue Dec 11 12:05:51 2007  Tanaka Akira  <akr@f...>
 
 	* encoding.c (rb_enc_get_ascii): add an argument to provide the
Index: transcode.c
===================================================================
--- transcode.c	(revision 14190)
+++ transcode.c	(revision 14191)
@@ -61,7 +61,7 @@
 typedef struct {
     const char *from_encoding;
     const char *to_encoding;
-    BYTE_LOOKUP *conv_tree_start;
+    const BYTE_LOOKUP *conv_tree_start;
     int max_output;
     int from_utf8;
 } transcoder;
@@ -86,7 +86,7 @@
     }
     transcoder_table[n].from_encoding = from_e;
     transcoder_table[n].to_encoding = to_e;
-    transcoder_table[n].conv_tree_start = (BYTE_LOOKUP *)tree_start;
+    transcoder_table[n].conv_tree_start = tree_start;
     transcoder_table[n].max_output = max_output;
     transcoder_table[n].from_utf8 = from_utf8;
 
@@ -168,19 +168,20 @@
     int from_utf8 = my_transcoder->from_utf8;
     char *out_s = out_stop - my_transcoder->max_output + 1;
     while (in_p < in_stop) {
-        next_table = conv_tree_start;
-        if (out_p >= out_s) {
+	next_table = conv_tree_start;
+	if (out_p >= out_s) {
 	    int len = (out_p - *out_pos);
 	    int new_len = (len + my_transcoder->max_output) * 2;
 	    *out_pos = (*my_transcoding->flush_func)(my_transcoding, len, new_len);
 	    out_p = *out_pos + len;
 	    out_s = *out_pos + new_len - my_transcoder->max_output;
-        }
-        next_byte = (unsigned char)*in_p++;
+	}
+	next_byte = (unsigned char)*in_p++;
       follow_byte:
-        next_offset = next_table->base[next_byte];
-        next_info = (VALUE)next_table->info[next_offset];
-        switch (next_info & 0x1F) {
+	next_offset = next_table->base[next_byte];
+	if (next_offset == (base_element)-1) goto illegal;
+	next_info = (VALUE)next_table->info[next_offset];
+	switch (next_info & 0x1F) {
 	  case NOMAP:
 	    *out_p++ = next_byte;
 	    continue;
@@ -223,13 +224,13 @@
 	    /* todo: add code for alternative behaviors */
 	    rb_raise(rb_eRuntimeError /*@@@change exception*/, "conversion undefined for byte sequence");
 	    continue;
-        }
-        continue;
+	}
+	continue;
       illegal:
-        /* deal with illegal byte sequence */
-        /* todo: add code for alternative behaviors */
-        rb_raise(rb_eRuntimeError /*change exception*/, "illegal byte sequence");
-        continue;
+	/* deal with illegal byte sequence */
+	/* todo: add code for alternative behaviors */
+	rb_raise(rb_eRuntimeError /*change exception*/, "illegal byte sequence");
+	continue;
     }
     /* cleanup */
     *in_pos  = in_p;
@@ -346,6 +347,7 @@
     VALUE newstr = str_transcode(argc, argv, str);
     if (NIL_P(newstr)) return str;
     rb_str_shared_replace(str, newstr);
+    rb_enc_copy(str, newstr);
     return str;
 }
 

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

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