Commit d2832063 authored by Paul Eggert's avatar Paul Eggert

Fix ungetc bug when reading an encoding error

* src/lread.c (readchar, read_emacs_mule_char): Fix off-by-one
error when reading an encoding error from a file, e.g., a symbol
in an .elc file whose name is "\360\220\200\360".
parent c819c053
...@@ -340,14 +340,13 @@ readchar (Lisp_Object readcharfun, bool *multibyte) ...@@ -340,14 +340,13 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
len = BYTES_BY_CHAR_HEAD (c); len = BYTES_BY_CHAR_HEAD (c);
while (i < len) while (i < len)
{ {
c = (*readbyte) (-1, readcharfun); buf[i++] = c = (*readbyte) (-1, readcharfun);
if (c < 0 || ! TRAILING_CODE_P (c)) if (c < 0 || ! TRAILING_CODE_P (c))
{ {
while (--i > 1) for (i -= c < 0; 0 < --i; )
(*readbyte) (buf[i], readcharfun); (*readbyte) (buf[i], readcharfun);
return BYTE8_TO_CHAR (buf[0]); return BYTE8_TO_CHAR (buf[0]);
} }
buf[i++] = c;
} }
return STRING_CHAR (buf); return STRING_CHAR (buf);
} }
...@@ -530,14 +529,13 @@ read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object rea ...@@ -530,14 +529,13 @@ read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object rea
buf[i++] = c; buf[i++] = c;
while (i < len) while (i < len)
{ {
c = (*readbyte) (-1, readcharfun); buf[i++] = c = (*readbyte) (-1, readcharfun);
if (c < 0xA0) if (c < 0xA0)
{ {
while (--i > 1) for (i -= c < 0; 0 < --i; )
(*readbyte) (buf[i], readcharfun); (*readbyte) (buf[i], readcharfun);
return BYTE8_TO_CHAR (buf[0]); return BYTE8_TO_CHAR (buf[0]);
} }
buf[i++] = c;
} }
if (len == 2) if (len == 2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment