changeset 36757:23382dbfb9d0

(read_multibyte): Check the validity of multibyte sequence. If invalid, return the first byte.
author Kenichi Handa <handa@m17n.org>
date Tue, 13 Mar 2001 06:04:12 +0000
parents bd3b761b45ba
children b96ce93cd7ab
files src/lread.c
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Tue Mar 13 06:03:52 2001 +0000
+++ b/src/lread.c	Tue Mar 13 06:04:12 2001 +0000
@@ -1506,13 +1506,20 @@
      characters.  */
   unsigned char str[MAX_MULTIBYTE_LENGTH];
   int len = 0;
+  int bytes;
 
   str[len++] = c;
   while ((c = READCHAR) >= 0xA0
 	 && len < MAX_MULTIBYTE_LENGTH)
     str[len++] = c;
   UNREAD (c);
-  return STRING_CHAR (str, len);
+  if (UNIBYTE_STR_AS_MULTIBYTE_P (str, len, bytes))
+    return STRING_CHAR (str, len);
+  /* The byte sequence is not valid as multibyte.  Unread all bytes
+     but the first one, and return the first byte.  */
+  while (--len > 0)
+    UNREAD (str[len]);
+  return str[0];
 }
 
 /* Read a \-escape sequence, assuming we already read the `\'.  */