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


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

Patch: Java lexer bug fix


Consider this test program:

    public class uesc
    {
      public foo (Object[] v[])
      {
	char z = '\uuu00a0';
	char y = '\u00au0';		// At one point we erroneously
				    // accepted this.
      }
    }

We erroneously accept this program.  The appended patch fixes the bug.
It also adds a regression test for this.

Ok for branch and trunk?

2001-03-20  Tom Tromey  <tromey@redhat.com>

	* lex.c (java_read_unicode): Only accept leading `u's.

2001-03-20  Tom Tromey  <tromey@redhat.com>

	* libjava.compile/uesc.java: New file.
	* libjava.compile/uesc.xfail: New file.

Tom

Index: gcc/java/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.60.2.1
diff -u -r1.60.2.1 lex.c
--- lex.c	2001/03/17 21:53:11	1.60.2.1
+++ lex.c	2001/03/21 00:05:41
@@ -532,6 +532,16 @@
         {
 	  unicode_t unicode = 0;
 	  int shift = 12;
+
+	  /* Recognize any number of `u's in \u.  */
+	  while ((c = java_read_char (lex)) == 'u')
+	    ;
+
+	  /* Unget the most recent character as it is not a `u'.  */
+	  if (c == UEOF)
+	    return UEOF;
+	  lex->unget_value = c;
+
 	  /* Next should be 4 hex digits, otherwise it's an error.
 	     The hex value is converted into the unicode, pushed into
 	     the Unicode stream.  */
@@ -543,11 +553,6 @@
 		unicode |= (unicode_t)((c-'0') << shift);
 	      else if ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
 	        unicode |= (unicode_t)((10+(c | 0x20)-'a') << shift);
-	      else if (c == 'u')
-		{
-		  /* Recognize any number of u in \u.  */
-		  shift += 4;
-		}
 	      else
 		java_lex_error ("Non hex digit in Unicode escape sequence", 0);
 	    }
Index: libjava/testsuite/libjava.compile/uesc.java
===================================================================
RCS file: uesc.java
diff -N uesc.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ uesc.java	Tue Mar 20 16:05:41 2001
@@ -0,0 +1,9 @@
+public class uesc
+{
+  public foo (Object[] v[])
+  {
+    char z = '\uuu00a0';
+    char y = '\u00au0';		// At one point we erroneously
+				// accepted this.
+  }
+}
Index: libjava/testsuite/libjava.compile/uesc.xfail
===================================================================
RCS file: uesc.xfail
diff -N uesc.xfail
--- /dev/null	Tue May  5 13:32:27 1998
+++ uesc.xfail	Tue Mar 20 16:05:41 2001
@@ -0,0 +1 @@
+shouldfail


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