Bison dumps core when trying to complain about broken input files.

Reported by Cris van Pelt.
* src/lex.c (parse_percent_token): Be sure to set token_buffer.
* tests/regression.at (Invalid input: 1, Invalid input: 2): Merge
into...
(Invalid inputs): Strengthen: exercise parse_percent_token.
This commit is contained in:
Akim Demaille
2002-01-24 17:09:34 +00:00
parent 2b548aa648
commit 29ae55f112
4 changed files with 42 additions and 30 deletions

View File

@@ -1,3 +1,13 @@
2002-01-24 Akim Demaille <akim@epita.fr>
Bison dumps core when trying to complain about broken input files.
Reported by Cris van Pelt.
* src/lex.c (parse_percent_token): Be sure to set token_buffer.
* tests/regression.at (Invalid input: 1, Invalid input: 2): Merge
into...
(Invalid inputs): Strengthen: exercise parse_percent_token.
2002-01-24 Robert Anisko <robert.anisko@epita.fr> 2002-01-24 Robert Anisko <robert.anisko@epita.fr>
* src/Makefile.am: Add bison.c++. * src/Makefile.am: Add bison.c++.

1
THANKS
View File

@@ -6,6 +6,7 @@ Akim Demaille akim@freefriends.org
Albert Chin-A-Young china@thewrittenword.com Albert Chin-A-Young china@thewrittenword.com
Alexander Belopolsky alexb@rentec.com Alexander Belopolsky alexb@rentec.com
Arnold Robbins arnold@skeeve.com Arnold Robbins arnold@skeeve.com
Cris van Pelt cris@amf03054.office.wxs.nl
Daniel Hagerty hag@gnu.org Daniel Hagerty hag@gnu.org
David J. MacKenzie djm@gnu.org David J. MacKenzie djm@gnu.org
Dick Streefland dick.streefland@altium.nl Dick Streefland dick.streefland@altium.nl

View File

@@ -482,43 +482,54 @@ parse_percent_token (void)
size_t arg_offset = 0; size_t arg_offset = 0;
int c = getc (finput); int c = getc (finput);
obstack_1grow (&token_obstack, '%');
obstack_1grow (&token_obstack, c);
switch (c) switch (c)
{ {
case '%': case '%':
token_buffer = obstack_finish (&token_obstack);
return tok_two_percents; return tok_two_percents;
case '{': case '{':
token_buffer = obstack_finish (&token_obstack);
return tok_percent_left_curly; return tok_percent_left_curly;
/* FIXME: Who the heck are those 5 guys!?! `%<' = `%left'!!! /* The following guys are here for backward compatibility with
Let's ask for there removal. */ very ancient Yacc versions. The paper of Johnson mentions
them (as ancient :). */
case '<': case '<':
token_buffer = obstack_finish (&token_obstack);
return tok_left; return tok_left;
case '>': case '>':
token_buffer = obstack_finish (&token_obstack);
return tok_right; return tok_right;
case '2': case '2':
token_buffer = obstack_finish (&token_obstack);
return tok_nonassoc; return tok_nonassoc;
case '0': case '0':
token_buffer = obstack_finish (&token_obstack);
return tok_token; return tok_token;
case '=': case '=':
token_buffer = obstack_finish (&token_obstack);
return tok_prec; return tok_prec;
} }
if (!isalpha (c)) if (!isalpha (c))
return tok_illegal; {
token_buffer = obstack_finish (&token_obstack);
return tok_illegal;
}
obstack_1grow (&token_obstack, '%'); while (c = getc (finput), isalpha (c) || c == '_' || c == '-')
while (isalpha (c) || c == '_' || c == '-')
{ {
if (c == '_') if (c == '_')
c = '-'; c = '-';
obstack_1grow (&token_obstack, c); obstack_1grow (&token_obstack, c);
c = getc (finput);
} }
/* %DIRECTIVE="ARG". Separate into /* %DIRECTIVE="ARG". Separate into

View File

@@ -501,40 +501,30 @@ AT_CLEANUP
## ----------------- ## ## ---------------- ##
## Invalid input 1. ## ## Invalid inputs. ##
## ----------------- ## ## ---------------- ##
AT_SETUP([Invalid input: 1]) AT_SETUP([Invalid inputs])
AT_DATA([input.y], AT_DATA([input.y],
[[%% [[%%
? ?
default: 'a' }
%{
%&
%a
%-
]]) ]])
AT_CHECK([bison input.y], [1], [], AT_CHECK([bison input.y], [1], [],
[[input.y:2: invalid input: `?' [[input.y:2: invalid input: `?'
input.y:3: fatal error: no rules in the input grammar input.y:3: invalid input: `}'
]]) input.y:4: invalid input: `%{'
input.y:5: invalid input: `%&'
AT_CLEANUP input.y:6: invalid input: `%a'
input.y:7: invalid input: `%-'
## ----------------- ##
## Invalid input 2. ##
## ----------------- ##
AT_SETUP([Invalid input: 2])
AT_DATA([input.y],
[[%%
default: 'a' }
]])
AT_CHECK([bison input.y], [1], [],
[[input.y:2: invalid input: `}'
]]) ]])
AT_CLEANUP AT_CLEANUP