In impure push mode, don't allow more than one yypstate to be allocated

since multiple impure parsers would corrupt yynerrs.
* data/push.c (yypstate_allocated): New static global variable
initialized to 0.
(yypull_parse): If yypstate_new returns 0, don't report it as memory
exhaustion if yypstate_allocated is 1, but still return 2.
(yypstate_new): Invoke yyerror and return 0 if yypstate_allocated is
already 1.  Otherwise, set it to 1.
(yypstate_delete): Set it to 0.
* tests/push.at (Push Parsing: Multiple impure instances): New test
case.
This commit is contained in:
Joel E. Denny
2007-08-18 00:45:52 +00:00
parent 9987d1b3cc
commit 1b17b01d0f
5 changed files with 231 additions and 131 deletions

View File

@@ -1076,7 +1076,9 @@ b4_push_if(
{
return yypull_parse (0]m4_ifset([b4_parse_param],
[[, ]b4_c_args(b4_parse_param)])[);
}
}]b4_pure_if([], [[
static char yypstate_allocated = 0;]])[
]b4_c_function_def([[yypull_parse]], [[int]],
[[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
@@ -1092,8 +1094,10 @@ b4_push_if(
{
yyps_local = yypstate_new ();
if (!yyps_local)
{
yyerror (]b4_yyerror_args[YY_("memory exhausted"));
{]b4_pure_if([[
yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[
if (!yypstate_allocated)
yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[
return 2;
}
}
@@ -1112,10 +1116,17 @@ b4_push_if(
/* Initialize the parser data structure. */
]b4_c_function_def([[yypstate_new]], [[yypstate *]])[
{
yypstate *yyps = (yypstate *) malloc (sizeof *yyps);
yypstate *yyps;]b4_pure_if([], [[
if (yypstate_allocated)
{
yyerror (]b4_yyerror_args[YY_("cannot allocate multiple impure push-parser instances"));
return 0;
}]])[
yyps = (yypstate *) malloc (sizeof *yyps);
if (!yyps)
return 0;
yyps->yynew = 1;
yyps->yynew = 1;]b4_pure_if([], [[
yypstate_allocated = 1;]])[
return yyps;
}
@@ -1128,7 +1139,8 @@ b4_push_if(
if (!yyps->yynew && yyps->yyss != yyps->yyssa)
YYSTACK_FREE (yyps->yyss);
#endif
free (yyps);
free (yyps);]b4_pure_if([], [[
yypstate_allocated = 0;]])[
}
]b4_pure_if([[#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs