[Top][All Lists]

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

Re: yacc.c fix to avoid use of uninitialized variables in initial action

From: Paul Eggert
Subject: Re: yacc.c fix to avoid use of uninitialized variables in initial action
Date: Sat, 09 Jul 2005 01:31:31 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Akim Demaille <address@hidden> writes:

> But then yylloc is no longer initialized.  I usually initialized
> it there, and then it is the scanner that updates it.  I really
> meant to have the previous version.

OK, I installed the following patch; it causes the generated
parser to copy yylloc to yylsp[0] only if the user initialization
code sets yylloc.

> And this value is not used, it is copied.  A tool such as Valgrind
> makes the difference.

Sorry, I don't quite follow this point.

We didn't find the problem with valgrind.  The problem was found
because GCC 4 is smart enough to warn that yylloc is used without
being initialized, when the initial action doesn't set the line

2005-07-09  Paul Eggert  <address@hidden>

        * data/yacc.c (yyparse): Undo previous patch.  Instead,
        set yylsp[0] and yyvsp[0] only if the initial action
        sets yylloc and yylval, respectively.

--- yacc.c      9 Jul 2005 07:14:18 -0000       1.93
+++ yacc.c      9 Jul 2005 08:26:29 -0000       1.94
@@ -859,16 +859,20 @@ b4_c_function_def([yyparse], [int], b4_p
 m4_ifdef([b4_initial_action], [
-m4_pushdef([b4_at_dollar],     [[yylsp[0]]])dnl
-m4_pushdef([b4_dollar_dollar], [[yyvsp[0]]])dnl
+m4_pushdef([b4_at_dollar],     [m4_define([b4_at_dollar_used])yylloc])dnl
+m4_pushdef([b4_dollar_dollar], [m4_define([b4_dollar_dollar_used])yylval])dnl
   /* User initialization code. */
 /* Line __line__ of yacc.c.  */
-b4_syncline(address@hidden@], address@hidden@])])dnl
-  goto yysetstate;
+b4_syncline(address@hidden@], address@hidden@])
+m4_ifdef([b4_dollar_dollar_used],[[  yyvsp[0] = yylval;
+m4_ifdef([b4_at_dollar_used], [[  yylsp[0] = yylloc;
+[  goto yysetstate;
 | yynewstate -- Push a new state, which is found in yystate.  |

reply via email to

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