From: Akim Demaille <akim@epita.fr>
Date: Thu, 24 Jan 2002 17:09:34 +0000 (+0000)
Subject: Bison dumps core when trying to complain about broken input files.
X-Git-Tag: before-m4-back-end~10
X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/29ae55f112c411438e778ccf2fd3fca8332ca0f2

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.
---

diff --git a/ChangeLog b/ChangeLog
index ac890dbb..c8283c97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
 	* src/Makefile.am: Add bison.c++.
diff --git a/THANKS b/THANKS
index e6424c84..7f378481 100644
--- a/THANKS
+++ b/THANKS
@@ -6,6 +6,7 @@ Akim Demaille           akim@freefriends.org
 Albert Chin-A-Young     china@thewrittenword.com
 Alexander Belopolsky    alexb@rentec.com
 Arnold Robbins		arnold@skeeve.com
+Cris van Pelt           cris@amf03054.office.wxs.nl
 Daniel Hagerty          hag@gnu.org
 David J. MacKenzie      djm@gnu.org
 Dick Streefland		dick.streefland@altium.nl
diff --git a/src/lex.c b/src/lex.c
index deb6eb7a..489fdf9c 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -482,43 +482,54 @@ parse_percent_token (void)
   size_t arg_offset = 0;
 
   int c = getc (finput);
+  obstack_1grow (&token_obstack, '%');
+  obstack_1grow (&token_obstack, c);
 
   switch (c)
     {
     case '%':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_two_percents;
 
     case '{':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_percent_left_curly;
 
-      /* FIXME: Who the heck are those 5 guys!?! `%<' = `%left'!!!
-	 Let's ask for there removal.  */
+      /* The following guys are here for backward compatibility with
+	 very ancient Yacc versions.  The paper of Johnson mentions
+	 them (as ancient :).  */
     case '<':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_left;
 
     case '>':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_right;
 
     case '2':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_nonassoc;
 
     case '0':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_token;
 
     case '=':
+      token_buffer = obstack_finish (&token_obstack);
       return tok_prec;
     }
 
   if (!isalpha (c))
-    return tok_illegal;
+    {
+      token_buffer = obstack_finish (&token_obstack);
+      return tok_illegal;
+    }
 
-  obstack_1grow (&token_obstack, '%');
-  while (isalpha (c) || c == '_' || c == '-')
+  while (c = getc (finput), isalpha (c) || c == '_' || c == '-')
     {
       if (c == '_')
 	c = '-';
       obstack_1grow (&token_obstack, c);
-      c = getc (finput);
     }
 
   /* %DIRECTIVE="ARG".  Separate into
diff --git a/tests/regression.at b/tests/regression.at
index 849f526c..9fadf50c 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -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_CHECK([bison input.y], [1], [],
-[[input.y:2: invalid input: `?'
-input.y:3: fatal error: no rules in the input grammar
-]])
-
-AT_CLEANUP
-
-
-## ----------------- ##
-## Invalid input 2.  ##
-## ----------------- ##
-
-
-AT_SETUP([Invalid input: 2])
-
-AT_DATA([input.y],
-[[%%
 default: 'a' }
+%{
+%&
+%a
+%-
 ]])
 
 AT_CHECK([bison input.y], [1], [],
-[[input.y:2: invalid input: `}'
+[[input.y:2: invalid input: `?'
+input.y:3: invalid input: `}'
+input.y:4: invalid input: `%{'
+input.y:5: invalid input: `%&'
+input.y:6: invalid input: `%a'
+input.y:7: invalid input: `%-'
 ]])
 
 AT_CLEANUP