mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 01:33:03 +00:00
(yyreportSyntaxError) [YYERROR_VERBOSE]:
Avoid subscript error in yycheck. Bug reported by Andrew Suffield in <http://mail.gnu.org/archive/html/bug-bison/2003-02/msg00003.html>. Check for malloc failure, for consistency with yacc.c. (yytname_size): Remove, for consistency with yacc.c.
This commit is contained in:
75
data/glr.c
75
data/glr.c
@@ -297,8 +297,6 @@ static const char *const yytname[] =
|
|||||||
{
|
{
|
||||||
]b4_tname[
|
]b4_tname[
|
||||||
};
|
};
|
||||||
|
|
||||||
#define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
|
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
|
||||||
@@ -1598,45 +1596,66 @@ yyreportSyntaxError (yyGLRStack* yystack,
|
|||||||
{
|
{
|
||||||
#if YYERROR_VERBOSE
|
#if YYERROR_VERBOSE
|
||||||
yySymbol* const yytokenp = yystack->yytokenp;
|
yySymbol* const yytokenp = yystack->yytokenp;
|
||||||
int yyn, yyx, yycount;
|
int yyn;
|
||||||
size_t yysize;
|
|
||||||
const char* yyprefix;
|
const char* yyprefix;
|
||||||
char* yyp;
|
|
||||||
char* yymsg;
|
|
||||||
yyn = yypact[yystack->yytops.yystates[0]->yylrState];
|
yyn = yypact[yystack->yytops.yystates[0]->yylrState];
|
||||||
if (YYPACT_NINF < yyn && yyn < YYLAST)
|
if (YYPACT_NINF < yyn && yyn < YYLAST)
|
||||||
{
|
{
|
||||||
yycount = 0;
|
size_t yysize = 0;
|
||||||
|
char* yymsg;
|
||||||
|
int yyx;
|
||||||
|
|
||||||
/* Start YYX at -YYN if negative to avoid negative indexes in
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
YYCHECK. */
|
YYCHECK. */
|
||||||
yysize = sizeof ("syntax error, unexpected ")
|
int yyxbase = yyn < 0 ? -yyn : 0;
|
||||||
+ strlen (yytokenName (*yytokenp));
|
|
||||||
|
/* Stay within bounds of both yycheck and yytname. */
|
||||||
|
int yychecklim = YYLAST - yyn;
|
||||||
|
int yynsyms = sizeof (yytname) / sizeof (yytname[0]);
|
||||||
|
int yyxlim = yychecklim < yynsyms ? yychecklim : yynsyms;
|
||||||
|
int yycount = 0;
|
||||||
|
|
||||||
yyprefix = ", expecting ";
|
yyprefix = ", expecting ";
|
||||||
for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
|
for (yyx = yyxbase; yyx < yyxlim && yycount < 5; yyx += 1)
|
||||||
yyx += 1)
|
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
|
{
|
||||||
yycount += 1, yyprefix = " or ";
|
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix);
|
||||||
yymsg = yyp = (char*) malloc (yysize);
|
yycount += 1;
|
||||||
sprintf (yyp, "syntax error, unexpected %s",
|
if (yycount == 5)
|
||||||
yytokenName (*yytokenp));
|
|
||||||
yyp += strlen (yyp);
|
|
||||||
if (yycount < 5)
|
|
||||||
{
|
|
||||||
yyprefix = ", expecting ";
|
|
||||||
for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size; yyx += 1)
|
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
|
||||||
{
|
{
|
||||||
sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
|
yysize = 0;
|
||||||
yyp += strlen (yyp);
|
break;
|
||||||
yyprefix = " or ";
|
|
||||||
}
|
}
|
||||||
|
yyprefix = " or ";
|
||||||
|
}
|
||||||
|
yysize += (sizeof ("syntax error, unexpected ")
|
||||||
|
+ strlen (yytokenName (*yytokenp)));
|
||||||
|
yymsg = (char*) malloc (yysize);
|
||||||
|
if (yymsg != 0)
|
||||||
|
{
|
||||||
|
char* yyp = yymsg;
|
||||||
|
sprintf (yyp, "syntax error, unexpected %s",
|
||||||
|
yytokenName (*yytokenp));
|
||||||
|
yyp += strlen (yyp);
|
||||||
|
if (yycount < 5)
|
||||||
|
{
|
||||||
|
yyprefix = ", expecting ";
|
||||||
|
for (yyx = yyxbase; yyx < yyxlim; yyx += 1)
|
||||||
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
|
{
|
||||||
|
sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
|
||||||
|
yyp += strlen (yyp);
|
||||||
|
yyprefix = " or ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yyerror (]b4_lyyerror_args[yymsg);
|
||||||
|
free (yymsg);
|
||||||
}
|
}
|
||||||
yyerror (]b4_lyyerror_args[yymsg);
|
else
|
||||||
free (yymsg);
|
yyerror (]b4_lyyerror_args["syntax error; also virtual memory exhausted");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif /* YYERROR_VERBOSE */
|
||||||
yyerror (]b4_lyyerror_args["syntax error");
|
yyerror (]b4_lyyerror_args["syntax error");
|
||||||
yynerrs += 1;
|
yynerrs += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user