This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: another java lexer fix


This fixes another two lexer bugs.

According to the grammar in the JLS, `\477' has a well-defined
meaning: it is `\47' followed by `7'.

Also, `8' and `9' are not valid octal digits.

Ok to commit?

2000-11-04  Tom Tromey  <tromey@cygnus.com>

	* lex.c (java_parse_escape_sequence): Only read two octal
	characters if the first one is greater than 3.  Don't allow
	"octal" numbers to include the digits 8 or 9.

Tom

Index: lex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/lex.c,v
retrieving revision 1.49
diff -u -r1.49 lex.c
--- lex.c	2000/11/03 20:27:07	1.49
+++ lex.c	2000/11/04 19:17:29
@@ -727,32 +727,32 @@
     case '\\':
       return (unicode_t)0x5c;
     case '0': case '1': case '2': case '3': case '4':
-    case '5': case '6': case '7': case '8': case '9':
+    case '5': case '6': case '7':
       {
 	int octal_escape[3];
 	int octal_escape_index = 0;
-	
-	for (; octal_escape_index < 3 && RANGE (c, '0', '9');
+	int max = 3;
+	int i, shift;
+
+	for (; octal_escape_index < max && RANGE (c, '0', '7');
 	     c = java_get_unicode ())
-	  octal_escape [octal_escape_index++] = c;
+	  {
+	    if (octal_escape_index == 0 && c > '3')
+	      {
+		/* According to the grammar, `\477' has a well-defined
+		   meaning -- it is `\47' followed by `7'.  */
+		--max;
+	      }
+	    octal_escape [octal_escape_index++] = c;
+	  }
 
 	java_unget_unicode ();
 
-	if ((octal_escape_index == 3) && (octal_escape [0] > '3'))
-	  {
-	    java_lex_error ("Literal octal escape out of range", 0);
-	    return JAVA_CHAR_ERROR;
-	  }
-	else
-	  {
-	    int i, shift;
-	    for (char_lit=0, i = 0, shift = 3*(octal_escape_index-1);
-		 i < octal_escape_index; i++, shift -= 3)
-	      char_lit |= (octal_escape [i] - '0') << shift;
+	for (char_lit=0, i = 0, shift = 3*(octal_escape_index-1);
+	     i < octal_escape_index; i++, shift -= 3)
+	  char_lit |= (octal_escape [i] - '0') << shift;
 
-	    return (char_lit);
-	  }
-	break;
+	return char_lit;
       }
     case '\n':
       return '\n';		/* ULT, caught latter as a specific error */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]