(yyerrlab) [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>.
This commit is contained in:
Paul Eggert
2003-02-13 07:13:57 +00:00
parent 7548fed236
commit 3aa2f55d71

View File

@@ -1039,17 +1039,34 @@ yyerrlab:
YYSIZE_T yysize = 0; YYSIZE_T yysize = 0;
int yytype = YYTRANSLATE (yychar); int yytype = YYTRANSLATE (yychar);
char *yymsg; char *yymsg;
int yyx, yycount; int yyx;
yycount = 0;
/* Start YYX at -YYN if negative to avoid negative indexes in /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. */
for (yyx = yyn < 0 ? -yyn : 0; int yyxbase = yyn < 0 ? -yyn : 0;
yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
/* 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;
for (yyx = yyxbase; yyx < yyxlim; yyx++)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
yysize += yystrlen (yytname[yyx]) + 15, yycount++; {
yysize += yystrlen ("syntax error, unexpected ") + 1; yysize += (! yycount
yysize += yystrlen (yytname[yytype]); ? sizeof (", expecting ") - 1
: sizeof (" or ") - 1);
yysize += yystrlen (yytname[yyx]);
yycount++;
if (yycount == 5)
{
yysize = 0;
break;
}
}
yysize += (sizeof ("syntax error, unexpected ")
+ yystrlen (yytname[yytype]));
yymsg = (char *) YYSTACK_ALLOC (yysize); yymsg = (char *) YYSTACK_ALLOC (yysize);
if (yymsg != 0) if (yymsg != 0)
{ {
@@ -1059,9 +1076,7 @@ yyerrlab:
if (yycount < 5) if (yycount < 5)
{ {
yycount = 0; yycount = 0;
for (yyx = yyn < 0 ? -yyn : 0; for (yyx = yyxbase; yyx < yyxlim; yyx++)
yyx < (int) (sizeof (yytname) / sizeof (char *));
yyx++)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{ {
const char *yyq = ! yycount ? ", expecting " : " or "; const char *yyq = ! yycount ? ", expecting " : " or ";