]> git.saurik.com Git - bison.git/commitdiff
* src/reader.c (copy_dollar, copy_at): Better checking of `n' in
authorAkim Demaille <akim@epita.fr>
Thu, 27 Dec 2001 18:07:31 +0000 (18:07 +0000)
committerAkim Demaille <akim@epita.fr>
Thu, 27 Dec 2001 18:07:31 +0000 (18:07 +0000)
`$n' and `@n'.

ChangeLog
src/reader.c

index 31d0477d6c8a61159453ac36a3f7a3156406f78c..ae882f37f8c8d3544d721fb59965e61961f12cee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-12-27  Akim Demaille  <akim@epita.fr>
+
+       * src/reader.c (copy_dollar, copy_at): Better checking of `n' in
+       `$n' and `@n'.
+
+       
 2001-12-27  Akim Demaille  <akim@epita.fr>
 
        * src/lalr.c (add_lookback_edge): Use state_t instead of ints.
index d19126240f06ea7577194c231a5fa1e08dd8899b..b09b3447d221ef1861287a94f8b8f4fe83c0a437 100644 (file)
@@ -334,9 +334,16 @@ copy_at (FILE *fin, struct obstack *oout, int stack_offset)
 
       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 @@ copy_dollar (FILE *fin, struct obstack *oout,
       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 (type_name)
-       obstack_fgrow1 (oout, ".%s", type_name);
-      if (!type_name && typed)
-       complain (_("$%d of `%s' has no declared type"),
-                 n, rule->sym->tag);
+      if (n > stack_offset)
+       complain (_("invalid value: %s%d"), "$", n);
+      else
+       {
+         if (!type_name && n > 0)
+           type_name = get_type_name (n, rule);
+
+         /* 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 @@ parse_thong_decl (void)
   nsyms--;
 }
 
+
 static void
 parse_muscle_decl (void)
 {
@@ -1081,8 +1097,8 @@ read_declarations (void)
 | 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.                 |
 `-------------------------------------------------------------------*/
 
@@ -1092,10 +1108,6 @@ parse_braces (symbol_list *rule, int stack_offset)
   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)
     {