bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bison glr skeleton SIGSEGV-avoiding patch


From: Miroslav Tichy
Subject: bison glr skeleton SIGSEGV-avoiding patch
Date: Tue, 18 Mar 2003 14:11:21 +0100
User-agent: Mutt/1.2.5.1i

Hello,

If you are using %glr-parser in your source
you can get an Segmentation Fault error from
the generated code.

The bug is hard to reproduce as it occurs with a large grammar
(modified ISO C++ grammar form ISO-14882:1998) and
lengthy input file (> 200K).

I do send a patch for glr.c -- glr parser template.
revision 1.53

This patch adresses case when there is a parse error and
the lookahead token is YYEMPTY (i.e. -2).
The original code just peeked at yytname[-2] and it failed.

Then an issue concerning sizeof("string")
it seemed that the correct meaning was strlen("string"),
not sizeof(char *).


--Miroslav Tichy
P.S. could you please replace @ with AT in ChangeLog if you accept
the patch?

--- glr.c-new   Tue Mar 18 13:55:10 2003
+++ glr.c       Sun Mar  2 14:39:44 2003
@@ -217,13 +217,11 @@
 [
 #ifdef __cplusplus
    typedef bool yybool;
-#  define yytrue true
-#  define yyfalse false
 #else
    typedef unsigned char yybool;
-#  define yytrue 1
-#  define yyfalse 0
 #endif
+#define yytrue 1
+#define yyfalse 0
 
 /*-----------------.
 | GCC extensions.  |
@@ -609,10 +607,6 @@
 static inline const char*
 yytokenName (yySymbol yytoken)
 {
-  if (yytoken == YYEMPTY)
-    return "$empty";
-  else if (yytoken < 0)
-    return "$unknown_lookahead_token";
   return yytname[yytoken];
 }
 #endif
@@ -1633,7 +1627,7 @@
                  }
                yyprefix = " or ";
              }
-         yysize += (strlen ("syntax error, unexpected ")
+         yysize += (sizeof ("syntax error, unexpected ")
                     + strlen (yytokenName (*yytokenp)));
          yymsg = (char*) malloc (yysize);
          if (yymsg != 0)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]