* data/glr.c (yyFail): Drastically simplify; since the format argument

never had any % directives, we can simply pass it to yyerror.
(yyparse): Use "t a; a=b;" rather than "t a = b;" when a will
be modified later, as that is the usual style in glr.c.
This commit is contained in:
Paul Eggert
2005-07-06 04:12:23 +00:00
parent 63cb01d656
commit fd2df2ede4
2 changed files with 12 additions and 30 deletions

View File

@@ -1,5 +1,11 @@
2005-07-05 Paul Eggert <eggert@cs.ucla.edu> 2005-07-05 Paul Eggert <eggert@cs.ucla.edu>
* data/glr.c (yyFail): Drastically simplify; since the format argument
never had any % directives, we can simply pass it to yyerror.
(yyparse): Use "t a; a=b;" rather than "t a = b;" when a will
be modified later, as that is the usual style in glr.c.
Problems reported by Paul Hilfinger.
Rewrite GLR parser to catch more buffer overrun, storage exhaustion, Rewrite GLR parser to catch more buffer overrun, storage exhaustion,
and size overflow errors. and size overflow errors.
* data/glr.c: Include <stdio.h> etc. after user prolog, not before, * data/glr.c: Include <stdio.h> etc. after user prolog, not before,

View File

@@ -678,37 +678,11 @@ struct yyGLRStack {
static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[); static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[);
static void static void
yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...) yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
{ {
yystack->yyerrflag = 1; yystack->yyerrflag = 1;
if (yyformat != NULL) if (yymsg != NULL)
{ yyerror (]b4_yyerror_args[yymsg);
char yysmallbuf[1024];
char const *yymsg = yysmallbuf;
char *yybigbuf = NULL;
int yymsglen;
va_list yyap;
va_start (yyap, yyformat);
yymsglen = vsnprintf (yysmallbuf, sizeof yysmallbuf, yyformat, yyap);
va_end (yyap);
if (yymsglen < 0)
yymsg = "message is too long to be printed";
else if (sizeof yysmallbuf <= yymsglen && yymsglen < YYSIZEMAX)
{
size_t yybigsize = yymsglen;
yybigsize++;
yymsg = yybigbuf = YYMALLOC (yybigsize);
va_start (yyap, yyformat);
vsnprintf (yybigbuf, yybigsize, yyformat, yyap);
va_end (yyap);
}
yyerror (]b4_yyerror_args[yymsg);
YYFREE (yybigbuf);
}
longjmp (yystack->yyexception_buffer, 1); longjmp (yystack->yyexception_buffer, 1);
} }
@@ -1973,7 +1947,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[ ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
{ {
yySymbol yytoken = YYEMPTY; yySymbol yytoken;
yyGLRStack yystack; yyGLRStack yystack;
size_t yyposn; size_t yyposn;
]b4_pure_if( ]b4_pure_if(
@@ -1989,6 +1963,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
YYDPRINTF ((stderr, "Starting parse\n")); YYDPRINTF ((stderr, "Starting parse\n"));
yytoken = YYEMPTY;
if (setjmp (yystack.yyexception_buffer) != 0) if (setjmp (yystack.yyexception_buffer) != 0)
goto yyDone; goto yyDone;