bison-patches
[Top][All Lists]
Advanced

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

diagnose NUL in Bison character constants and string literals


From: Paul Eggert
Subject: diagnose NUL in Bison character constants and string literals
Date: 07 Oct 2003 00:42:56 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I installed the following patch so that "'\0'" in grammars doesn't
result in bizarre parser crashes like the one described in
<http://mail.gnu.org/archive/html/help-bison/2003-03/msg00062.html>.

I suppose we should extend Bison to allow NUL in string literals and
character constants, since the GNU coding style recommends support for
NUL everywhere.  But I'd rather wait until after the next release for
that.

2003-10-07  Paul Eggert  <address@hidden>

        * doc/bison.texinfo (Symbols): NUL bytes are not allowed in string
        literals, unfortunately.
        * src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>):
        Complain about NUL bytes in character constants or string literals.

Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.115
diff -p -u -r1.115 bison.texinfo
--- doc/bison.texinfo   5 Oct 2003 07:34:36 -0000       1.115
+++ doc/bison.texinfo   7 Oct 2003 07:25:31 -0000
@@ -2481,7 +2481,8 @@ does not enforce this convention, but if
 read your program will be confused.
 
 All the escape sequences used in string literals in C can be used in
-Bison as well.  However, unlike Standard C, trigraphs have no special
+Bison as well, except that you must not use a null character within a
+string literal.  Also, unlike Standard C, trigraphs have no special
 meaning in Bison string literals, nor is backslash-newline allowed.  A
 literal string token must contain two or more characters; for a token
 containing just one character, use a character token (see above).
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.65
diff -p -u -r1.65 scan-gram.l
--- src/scan-gram.l     1 Oct 2003 21:33:24 -0000       1.65
+++ src/scan-gram.l     7 Oct 2003 07:25:36 -0000
@@ -371,6 +371,7 @@ splice       (\\[ \f\t\v]*\n)*
     return STRING;
   }
 
+  \0       complain_at (*loc, _("invalid null character"));
   .|\n     STRING_GROW;
   <<EOF>>   unexpected_eof (token_start, "\""); BEGIN INITIAL;
 }
@@ -397,6 +398,7 @@ splice       (\\[ \f\t\v]*\n)*
     return ID;
   }
 
+  \0       complain_at (*loc, _("invalid null character"));
   .|\n     STRING_GROW;
   <<EOF>>   unexpected_eof (token_start, "'"); BEGIN INITIAL;
 }
@@ -412,6 +414,8 @@ splice       (\\[ \f\t\v]*\n)*
     unsigned long c = strtoul (yytext + 1, 0, 8);
     if (UCHAR_MAX < c)
       complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
+    else if (! c) 
+      complain_at (*loc, _("invalid null character: %s"), quote (yytext));
     else
       obstack_1grow (&obstack_for_string, c);
   }
@@ -422,6 +426,8 @@ splice       (\\[ \f\t\v]*\n)*
     c = strtoul (yytext + 2, 0, 16);
     if (UCHAR_MAX < c || get_errno ())
       complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
+    else if (! c)
+      complain_at (*loc, _("invalid null character: %s"), quote (yytext));
     else
       obstack_1grow (&obstack_for_string, c);
   }
@@ -441,6 +447,8 @@ splice       (\\[ \f\t\v]*\n)*
     int c = convert_ucn_to_byte (yytext);
     if (c < 0)
       complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
+    else if (! c)
+      complain_at (*loc, _("invalid null character: %s"), quote (yytext));
     else
       obstack_1grow (&obstack_for_string, c);
   }




reply via email to

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