I'm working with bison 2.0 (release).
It generates the following code:

---
yyabortlab:
  yydestruct("Error: discarding lookahead", yytoken, &yylval);
  yychar = YYEMPTY;
  yyresult = 1;
  goto yyreturn;
---

One could argue why setting yychar = YYEMPTY is necessary, since the very next 
step is returning from the function, but more importantly, I have crashes in 
some cases where the lookahead item is destructed twice.
I could fix my crashes by changing the above fragment to:

---
yyabortlab:
  if (yychar != YYEOF && yychar != YYEMPTY)  
    yydestruct("Error: discarding lookahead", yytoken, &yylval);
  yychar = YYEMPTY;
  yyresult = 1;
  goto yyreturn;
---

I do not nearly oversee all bison cases, so I don't want to propose this as a 
'bug fix' (maybe it creates new bugs :-)). But my crash is fixed, and my 
understanding is that yylval and yytoken _depend_ on yychar (i.e. if yychar 
is YYEMPTY, yytoken and yylval are undefined). So we should check yychar 
before calling yydestruct() to free the yylval lookahead token.

Regards,
Wolfgang Spraul


Reply via email to