Patch: False syntax error (illegal 0377 character that's not there).

Donn Terry donn@interix.com
Tue May 4 08:09:00 GMT 1999


-- 

===================================================
Donn Terry                  mailto:donn@interix.com
Softway Systems, Inc.        http://www.interix.com
2850 McClelland Dr, Ste. 1800   Ft.Collins CO 80525
Tel: +1-970-204-9900           Fax: +1-970-204-9951
===================================================
False syntax error (illegal 0377 character that's not there).

Problem:
On test 950922-1.c the compiler upon occasion reports finding an illegal
character.  (This is apparently unrelated to the purpose of the test.)

Cause:
In c-lex.c: it turns out that if an EOF is reported by getc(), under
some circumstances it can be pushed back with UNGETC().  However, when
not using the new cpp stuff, UNGETC is just ungetc(), which takes an
ordinary character as input.  (Seen with position_after_white_space's
call to skip_white_space()).  

A subsequent getc() will return the EOF flag, now downsized to a char.
(If EOF==-1, then the character read back is 0377).  Ungetc is also defined
to turn off the EOF condition.


Fix: Change UNGETC() to be a no-op if an EOF is being pushed back.
(It's that or changing all the calls to special case EOF, which doesn't
fit will with the new cpp stuff.) 

Watch out for possible side-effecs in one use of the macro.

ChangeLog:

Mon May 3 21:05:41 1999 Donn Terry (donn@interix.com)

	* c-lex.c (UNGETC): Do nothing if attempting to push back EOF.
	(position_after_whiate_space): Avoid double evaluation.

diff -urP egcs.source.old/gcc/c-lex.c egcs.source/gcc/c-lex.c
--- egcs.source.old/gcc/c-lex.c	Fri Apr  9 10:02:41 1999
+++ egcs.source/gcc/c-lex.c	Mon May  3 21:03:53 1999
@@ -73,7 +73,7 @@ extern int yy_get_token ();
 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
 #else
 #define GETC() getc (finput)
-#define UNGETC(c) ungetc (c, finput)
+#define UNGETC(c) ((c) == EOF ? 0 : ungetc (c, finput))
 #endif
 
 /* the declaration found for the last IDENTIFIER token read in.
@@ -442,7 +442,8 @@ position_after_white_space ()
 #endif
     c = GETC();
 
-  UNGETC (skip_white_space (c));
+  c = skip_white_space (c);
+  UNGETC (c);
 }
 
 /* Like skip_white_space, but don't advance beyond the end of line.


More information about the Gcc-patches mailing list