bison-patches
[Top][All Lists]
Advanced

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

12-fyi-at-and-dollar-n.patch


From: Akim Demaille
Subject: 12-fyi-at-and-dollar-n.patch
Date: Thu, 27 Dec 2001 19:01:44 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * src/reader.c (copy_dollar, copy_at): Better checking of `n' in
        `$n' and address@hidden'.
        
        
Index: src/reader.c
--- src/reader.c Wed, 26 Dec 2001 20:07:27 +0100 akim
+++ src/reader.c Wed, 26 Dec 2001 22:11:13 +0100 akim
@@ -334,9 +334,16 @@
 
       ungetc (c, fin);
       n = read_signed_integer (fin);
-
-      obstack_fgrow1 (oout, "yylsp[%d]", n - stack_offset);
-      locations_flag = 1;
+      if (n > stack_offset)
+       complain (_("invalid value: %s%d"), "@", n);
+      else
+       {
+         /* Offset is always 0 if parser has already popped the stack
+            pointer.  */
+         obstack_fgrow1 (oout, "yylsp[%d]",
+                         n - (semantic_parser ? 0 : stack_offset));
+         locations_flag = 1;
+       }
     }
   else
     {
@@ -391,16 +398,24 @@
       ungetc (c, fin);
       n = read_signed_integer (fin);
 
-      if (!type_name && n > 0)
-       type_name = get_type_name (n, rule);
-
-      obstack_fgrow1 (oout, "yyvsp[%d]", n - stack_offset);
+      if (n > stack_offset)
+       complain (_("invalid value: %s%d"), "$", n);
+      else
+       {
+         if (!type_name && n > 0)
+           type_name = get_type_name (n, rule);
 
-      if (type_name)
-       obstack_fgrow1 (oout, ".%s", type_name);
-      if (!type_name && typed)
-       complain (_("$%d of `%s' has no declared type"),
-                 n, rule->sym->tag);
+         /* Offset is always 0 if parser has already popped the stack
+            pointer.  */
+         obstack_fgrow1 (oout, "yyvsp[%d]",
+                         n - (semantic_parser ? 0 : stack_offset));
+
+         if (type_name)
+           obstack_fgrow1 (oout, ".%s", type_name);
+         if (!type_name && typed)
+           complain (_("$%d of `%s' has no declared type"),
+                     n, rule->sym->tag);
+       }
     }
   else
     {
@@ -882,6 +897,7 @@
   nsyms--;
 }
 
+
 static void
 parse_muscle_decl (void)
 {
@@ -1081,8 +1097,8 @@
 | values in the current rule so far, which says where to find `$0'   |
 | with respect to the top of the stack.                              |
 |                                                                    |
-| This routine is used both for actions and guards.  Only the        |
-| actions_obstack is used, but this is fine, since we use only       |
+| This routine is used both for actions and guards.  Only            |
+| ACTION_OBSTACK is used, but this is fine, since we use only        |
 | pointers to relevant portions inside this obstack.                 |
 `-------------------------------------------------------------------*/
 
@@ -1091,10 +1107,6 @@
 {
   int c;
   int count;
-
-  /* offset is always 0 if parser has already popped the stack pointer */
-  if (semantic_parser)
-    stack_offset = 0;
 
   count = 1;
   while (count > 0)



reply via email to

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