skeletons: beware not to use yyarg when it's null

Reported by Adrian Vogelsgesang.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Here.
This commit is contained in:
Akim Demaille
2020-04-06 18:37:51 +02:00
parent 11225a5d2f
commit 87579e03e0
5 changed files with 11 additions and 7 deletions

3
TODO
View File

@@ -1,7 +1,4 @@
* Bison 3.6
** syntax_error_arguments
Don't store the lookahead if !argv.
** Documentation
- yyexpected_tokens in all the languages.
- YYNOMEM

View File

@@ -2188,7 +2188,9 @@ yy_syntax_error_arguments (const yyGLRStack* yystackp,
if (yytoken != YYSYMBOL_YYEMPTY)
{
int yyn;
yyarg[yycount++] = yytoken;
if (yyarg)
yyarg[yycount] = yytoken;
++yycount;
yyn = yyexpected_tokens (yystackp, yyarg ? yyarg + 1 : yyarg, yyargn - 1);
if (yyn == YYNOMEM)
return YYNOMEM;

View File

@@ -1458,7 +1458,8 @@ b4_dollar_popdef])[]dnl
if (!yyctx.lookahead ().empty ())
{
yyarg[0] = yyctx.token ();
if (yyarg)
yyarg[0] = yyctx.token ();
int yyn = yyctx.yyexpected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1);
return yyn + 1;
}

View File

@@ -981,7 +981,9 @@ b4_dollar_popdef[]dnl
int yycount = 0;
if (yyctx.getToken () != null)
{
yyarg[yycount++] = yyctx.getToken ();
if (yyarg != null)
yyarg[yycount] = yyctx.getToken ();
yycount += 1;
yycount += yyctx.getExpectedTokens (yyarg, 1, yyargn);
}
return yycount;

View File

@@ -1360,7 +1360,9 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx,
{
int yyn;]b4_lac_if([[
YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
yyarg[yycount++] = yyctx->yytoken;
if (yyarg)
yyarg[yycount] = yyctx->yytoken;
++yycount;
yyn = yyexpected_tokens (yyctx, yyarg ? yyarg + 1 : yyarg, yyargn - 1);
if (yyn == YYNOMEM)
return YYNOMEM;]b4_lac_if([[