lex.c (java_read_char): UNGET invalid non-initial utf8 character.
authorPer Bothner <bothner@gcc.gnu.org>
Sat, 13 Mar 1999 19:21:38 +0000 (11:21 -0800)
committerPer Bothner <bothner@gcc.gnu.org>
Sat, 13 Mar 1999 19:21:38 +0000 (11:21 -0800)
h
* lex.c (java_read_char):  UNGET invalid non-initial utf8 character.
* lex.h (UNGETC):  Change misleading macro.

From-SVN: r25753

gcc/java/lex.c
gcc/java/lex.h

index 8c40d47ac69eae7b843cf3c8cc08d847f505b15f..54708adb08e45f5d0ac1a18cc21397d5e5bc2c95 100644 (file)
@@ -227,6 +227,7 @@ java_read_char ()
           c1 = GETC ();
          if ((c1 & 0xc0) == 0x80)
            return (unicode_t)(((c &0x1f) << 6) + (c1 & 0x3f));
+         c = c1;
        }
       else if ((c & 0xf0) == 0xe0)
         {
@@ -237,8 +238,18 @@ java_read_char ()
              if ((c2 & 0xc0) == 0x80)
                return (unicode_t)(((c & 0xf) << 12) + 
                                   (( c1 & 0x3f) << 6) + (c2 & 0x3f));
+             else
+               c = c2;
            }
+         else
+           c = c1;
        }
+      /* We looked for a UTF8 multi-byte sequence (since we saw an initial
+        byte with the high bit set), but found invalid bytes instead.
+        If the most recent byte was Ascii (and not EOF), we should
+        unget it, in case it was a comment terminator or other delimitor. */
+      if ((c & 0x80) == 0)
+       UNGETC (c);
       return BAD_UTF8_VALUE;
     }
 }
@@ -308,7 +319,7 @@ java_read_unicode (term_context, unicode_escape_p)
          return (term_context ? unicode :
                  (java_lineterminator (c) ? '\n' : unicode));
        }
-      UNGETC (c);
+      ctxp->unget_utf8_value = c;
     }
   return (unicode_t)'\\';
 }
index 42cb1c4cfaa2dc3edae9f0b78c7167b11da87f59..d40196e2c53c1451539e92029e64e69d03c07fa7 100644 (file)
@@ -99,8 +99,8 @@ typedef struct _java_lc {
 
 #define JAVA_LINE_MAX 80
 
-/* Macro to read and unread chars */
-#define UNGETC(c) ctxp->unget_utf8_value = (c);
+/* Macro to read and unread bytes */
+#define UNGETC(c) ungetc(c, finput)
 #define GETC()    getc(finput)
 
 /* Build a location compound integer */