changeset 30581:6c7a9202a815

(coding_restore_composition): Pay attention to the case that cmp_data is not set properly (because of invalid code in the source text). (run_pre_post_conversion_on_str): Include text properties in the resulting string. (decode_coding_string): Set members of coding correctly.
author Kenichi Handa <handa@m17n.org>
date Fri, 04 Aug 2000 05:53:01 +0000
parents 5d92193ed196
children 280157ad4aa3
files src/coding.c
diffstat 1 files changed, 32 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/coding.c	Fri Aug 04 02:26:32 2000 +0000
+++ b/src/coding.c	Fri Aug 04 05:53:01 2000 +0000
@@ -4660,7 +4660,8 @@
     {
       int i;
 
-      for (i = 0; i < cmp_data->used; i += cmp_data->data[i])
+      for (i = 0; i < cmp_data->used && cmp_data->data[i] > 0;
+	   i += cmp_data->data[i])
 	{
 	  int *data = cmp_data->data + i;
 	  enum composition_method method = (enum composition_method) data[3];
@@ -5184,7 +5185,7 @@
       call1 (coding->post_read_conversion, make_number (Z - BEG));
     }
   inhibit_pre_post_conversion = 0;
-  str = make_buffer_string (BEG, Z, 0);
+  str = make_buffer_string (BEG, Z, 1);
   return unbind_to (count, str);
 }
 
@@ -5200,6 +5201,7 @@
   struct gcpro gcpro1;
   Lisp_Object saved_coding_symbol;
   int result;
+  int require_decoding;
 
   from = 0;
   to = XSTRING (str)->size;
@@ -5228,15 +5230,7 @@
 	}
     }
 
-  if (! CODING_REQUIRE_DECODING (coding))
-    {
-      if (!STRING_MULTIBYTE (str))
-	{
-	  str = Fstring_as_multibyte (str);
-	  nocopy = 1;
-	}
-      return (nocopy ? str : Fcopy_sequence (str));
-    }
+  require_decoding = CODING_REQUIRE_DECODING (coding);
 
   if (STRING_MULTIBYTE (str))
     {
@@ -5244,24 +5238,39 @@
       str = Fstring_as_unibyte (str);
       to_byte = STRING_BYTES (XSTRING (str));
       nocopy = 1;
-      coding->src_multibyte = 0;
     }
-  coding->dst_multibyte = 1;
-
-  if (coding->composing != COMPOSITION_DISABLED)
-    coding_allocate_composition_data (coding, from);
+  coding->src_multibyte = 0;
+  coding->dst_multibyte = (coding->type != coding_type_no_conversion
+			   && coding->type != coding_type_raw_text);
 
   /* Try to skip the heading and tailing ASCIIs.  */
-  if (coding->type != coding_type_ccl)
+  if (require_decoding && coding->type != coding_type_ccl)
     {
       int from_orig = from;
 
       SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data,
 				0);
       if (from == to_byte)
-	return (nocopy ? str : Fcopy_sequence (str));
+	require_decoding = 0;
     }
 
+  if (!require_decoding)
+    {
+      coding->consumed = STRING_BYTES (XSTRING (str));
+      coding->consumed_char = XSTRING (str)->size;
+      if (coding->dst_multibyte)
+	{
+	  str = Fstring_as_multibyte (str);
+	  nocopy = 1;
+	}
+      coding->produced = STRING_BYTES (XSTRING (str));
+      coding->produced_char = XSTRING (str)->size;
+      return (nocopy ? str : Fcopy_sequence (str));
+    }
+
+  if (coding->composing != COMPOSITION_DISABLED)
+    coding_allocate_composition_data (coding, from);
+
   len = decoding_buffer_size (coding, to_byte - from);
   len += from + STRING_BYTES (XSTRING (str)) - to_byte;
   GCPRO1 (str);
@@ -5286,8 +5295,11 @@
 	 STRING_BYTES (XSTRING (str)) - to_byte);
 
   len = from + STRING_BYTES (XSTRING (str)) - to_byte;
-  str = make_multibyte_string (buf, len + coding->produced_char,
-			       len + coding->produced);
+  if (coding->dst_multibyte)
+    str = make_multibyte_string (buf, len + coding->produced_char,
+				 len + coding->produced);
+  else
+    str = make_unibyte_string (buf, len + coding->produced);
 
   if (coding->cmp_data && coding->cmp_data->used)
     coding_restore_composition (coding, str);