bug-bison
[Top][All Lists]
Advanced

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

minor violation of the C standard in Bison 1.28c output file


From: Paul Eggert
Subject: minor violation of the C standard in Bison 1.28c output file
Date: Fri, 17 Aug 2001 17:07:02 -0700 (PDT)

I found this bug by hand, when using Bison to teach an undergraduate
course on compiler construction.

Bison 1.28c generates code that looks like this:

  short yyssa[YYINITDEPTH];
  short *yyss = yyssa;
  register short *yyssp;
  ...
  yyssp = yyss - 1;

This violates the C standard, because it causes `yyssp' to point one
before the start of the array `yyssa', and the C standard says that
the resulting behavior is undefined.  Portable C code can point one
after the end of an array, but it cannot point to one before the start
of the array, even if the code does not dereference the invalid pointer.

Here is a patch.

2001-08-17  Paul Eggert  <address@hidden>

        * src/bison.simple (yyparse): Don't take the address of an
        item before the start of an array, as that doesn't conform to
        the C Standard.

===================================================================
RCS file: src/bison.simple,v
retrieving revision 1.28.3.0
retrieving revision 1.28.3.1
diff -pu -r1.28.3.0 -r1.28.3.1
--- src/bison.simple    2001/08/15 07:56:20     1.28.3.0
+++ src/bison.simple    2001/08/17 23:58:49     1.28.3.1
@@ -343,11 +343,12 @@ yyparse (YYPARSE_PARAM_ARG)
      so that they stay on the same level as the state stack.
      The wasted elements are never initialized.  */
 
-  yyssp = yyss - 1;
+  yyssp = yyss;
   yyvsp = yyvs;
 #if YYLSP_NEEDED
   yylsp = yyls;
 #endif
+  goto yysetstate;
 
 
 /*------------------------------------------------------------.
@@ -357,7 +358,10 @@ yynewstate:
   /* In all cases, when you get here, the value and location stacks
      have just been pushed. so pushing a state here evens the stacks.
      */
-  *++yyssp = yystate;
+  yyssp++;
+
+yysetstate:
+  *yyssp = yystate;
 
   if (yyssp >= yyss + yystacksize - 1)
     {



reply via email to

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