bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

invalid @N values


From: Florian Krohm
Subject: invalid @N values
Date: Thu, 31 Jan 2002 14:20:06 -0500 (EST)

Bison 1.32 does not complain about invalid @N values as it 
does for invalid $N values.
Here is a grammar that exercises this behavior.

%locations
%%
foo: { $1, @1; }
;

Attached is a patch of bison-1.32.tar.gz that corrects this.
Note, that no paperwork is on file. But I suppose that the
trivial nature of the patch does not require it. 

Florian


diff -r --unif=3 bison-1.32/ChangeLog bison-1.32a/ChangeLog
--- bison-1.32/ChangeLog        Wed Jan 23 08:30:41 2002
+++ bison-1.32a/ChangeLog       Thu Jan 31 13:56:03 2002
@@ -1,3 +1,7 @@
+2002-01-31  Florian Krohm  <address@hidden>
+
+       * src/reader.c (copy_at): Detect invalid @N values.
+
 2002-01-23  Akim Demaille  <address@hidden>
 
        Version 1.32.
diff -r --unif=3 bison-1.32/src/reader.c bison-1.32a/src/reader.c
--- bison-1.32/src/reader.c     Mon Jan  7 03:41:03 2002
+++ bison-1.32a/src/reader.c    Thu Jan 31 13:53:32 2002
@@ -304,13 +304,15 @@
 /*-----------------------------------------------------------------.
 | FIN is pointing to a location (i.e., a `@').  Output to OOUT a   |
 | reference to this location. STACK_OFFSET is the number of values |
-| in the current rule so far, which says where to find `$0' with   |
+| in the current rule so far, which says where to find address@hidden' with   |
 | respect to the top of the stack.                                 |
 `-----------------------------------------------------------------*/
 
 static inline void
-copy_at (FILE *fin, struct obstack *oout, int stack_offset)
+copy_at (FILE *fin, struct obstack *oout,
+        struct symbol_list *rule, int stack_offset)
 {
+  symbol_list *rp;
   int c;
 
   c = getc (fin);
@@ -321,11 +323,25 @@
     }
   else if (isdigit (c) || c == '-')
     {
-      int n;
+      int n, i;
 
       ungetc (c, fin);
       n = read_signed_integer (fin);
 
+      rp = rule;
+      i = 0;
+
+      while (i < n)
+       {
+         rp = rp->next;
+         if (rp == NULL)
+           {
+             complain (_("invalid @ value"));
+             return;
+           }
+         i++;
+       }
+
       obstack_fgrow1 (oout, "yylsp[%d]", n - stack_offset);
       locations_flag = 1;
     }
@@ -1103,7 +1119,7 @@
 
            case '@':
              copy_at (finput, &action_obstack,
-                      stack_offset);
+                      rule, stack_offset);
              break;
 
            case EOF:
@@ -1203,7 +1219,7 @@
          break;
 
        case '@':
-         copy_at (finput, &guard_obstack, stack_offset);
+         copy_at (finput, &guard_obstack, rule, stack_offset);
          break;
 
        case EOF:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]