* tests/actions.at: Test that stack overflow invokes destructors.

From Marcus Holland-Moritz.
* data/yacc.c (yyerrlab): Move the code that destroys the stack
from here....
(yyreturn): to here.  That way, destructors are called properly
even if the stack overflows, or the user calls YYACCEPT or
YYABORT.  Stack-overflow problem reported by Marcus Holland-Moritz.
(yyoverflowlab): Destroy the lookahead.
This commit is contained in:
Paul Eggert
2005-05-02 04:52:33 +00:00
parent b9c9f76197
commit 80ce3401e9
3 changed files with 84 additions and 10 deletions

View File

@@ -1,3 +1,18 @@
2005-05-01 Paul Eggert <eggert@cs.ucla.edu>
* tests/actions.at: Test that stack overflow invokes destructors.
From Marcus Holland-Moritz.
* data/yacc.c (yyerrlab): Move the code that destroys the stack
from here....
(yyreturn): to here. That way, destructors are called properly
even if the stack overflows, or the user calls YYACCEPT or
YYABORT. Stack-overflow problem reported by Marcus Holland-Moritz.
(yyoverflowlab): Destroy the lookahead.
2005-04-24 Paul Eggert <eggert@cs.ucla.edu>
* data/yacc.c (YYSTACK_ALLOC_MAXIMUM): Add more-descriptive comment.
2005-04-17 Paul Eggert <eggert@cs.ucla.edu>
* NEWS: Bison-generated C parsers no longer quote literal strings

View File

@@ -1203,15 +1203,7 @@ yyerrlab:
/* If at end of input, pop the error token,
then the rest of the stack, then return failure. */
if (yychar == YYEOF)
for (;;)
{
]b4_location_if([[ yyerror_range[0] = *yylsp;]])[
YYPOPSTACK;
if (yyssp == yyss)
YYABORT;
yydestruct (_("Error: popping"),
yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
}
YYABORT;
}
else
{
@@ -1316,11 +1308,23 @@ yyabortlab:
`----------------------------------------------*/
yyoverflowlab:
yyerror (]b4_yyerror_args[_("parser stack overflow"));
yydestruct (_("Error: discarding lookahead"),
yytoken, &yylval]b4_location_if([, &yylloc])[);
yyresult = 2;
/* Fall through. */
#endif
yyreturn:
if (yyssp != yyss)
for (;;)
{
]b4_location_if([[ yyerror_range[0] = *yylsp;]])[
YYPOPSTACK;
if (yyssp == yyss)
break;
yydestruct (_("Error: popping"),
yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);

View File

@@ -1,5 +1,5 @@
# Executing Actions. -*- Autotest -*-
# Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
# Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -174,6 +174,9 @@ AT_DATA_GRAMMAR([[input.y]],
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define YYINITDEPTH 10
#define YYMAXDEPTH 10
]AT_LALR1_CC_IF(
[#define RANGE(Location) (Location).begin.line, (Location).end.line],
[#define RANGE(Location) (Location).first_line, (Location).last_line])
@@ -442,6 +445,58 @@ Freeing token 'y' (13@130-139)
Parsing FAILED.
]])
# Check destruction upon stack overflow
# -------------------------------------
# Upon stack overflow, all symbols on the stack should be destroyed.
# Only check for yacc.c.
AT_YACC_IF([
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 1,
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
sending: ')' (2@20-29)
line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
sending: '(' (3@30-39)
sending: 'x' (4@40-49)
thing (4@40-49): 'x' (4@40-49)
sending: ')' (5@50-59)
line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
sending: '(' (6@60-69)
sending: 'x' (7@70-79)
thing (7@70-79): 'x' (7@70-79)
sending: ')' (8@80-89)
line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
sending: '(' (9@90-99)
sending: 'x' (10@100-109)
thing (10@100-109): 'x' (10@100-109)
sending: ')' (11@110-119)
line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
sending: '(' (12@120-129)
sending: 'x' (13@130-139)
thing (13@130-139): 'x' (13@130-139)
sending: ')' (14@140-149)
line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
sending: '(' (15@150-159)
sending: 'x' (16@160-169)
thing (16@160-169): 'x' (16@160-169)
sending: ')' (17@170-179)
line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
sending: '(' (18@180-189)
sending: 'x' (19@190-199)
thing (19@190-199): 'x' (19@190-199)
sending: ')' (20@200-209)
200-209: parser stack overflow
Freeing nterm thing (19@190-199)
Freeing nterm line (15@150-179)
Freeing nterm line (12@120-149)
Freeing nterm line (9@90-119)
Freeing nterm line (6@60-89)
Freeing nterm line (3@30-59)
Freeing nterm line (0@0-29)
Parsing FAILED.
]])
])
])