mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
escape properly the file names in #line for printer/destructor
Reported by Jannick. http://lists.gnu.org/archive/html/bug-bison/2017-05/msg00001.html "Amusingly" enough, we have the same problem with %defines when the parser file name has backslashes or quotes: we generate #includes with an incorrect C string. * src/output.c (prepare_symbol_definitions): Escape properly the file names before passing them to M4. * data/bison.m4, data/lalr1.cc: Don't simply put the file name between two quotes (that should have been strong enough a smell...), expect the string to be properly quoted. * tests/synclines.at: New tests to check this.
This commit is contained in:
6
NEWS
6
NEWS
@@ -86,6 +86,12 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
were issued with #lines in the middle of C code.
|
were issued with #lines in the middle of C code.
|
||||||
|
|
||||||
|
*** Printer and destructor with broken #line directives
|
||||||
|
|
||||||
|
The #line directives were not properly escaped when emitting the code for
|
||||||
|
%printer/%destructor, which resulted in compiler errors if there are
|
||||||
|
backslashes or double-quotes in the grammar file name.
|
||||||
|
|
||||||
* Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
|
* Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
|
||||||
|
|
||||||
** Bug fixes
|
** Bug fixes
|
||||||
|
|||||||
1
THANKS
1
THANKS
@@ -64,6 +64,7 @@ Guido Trentalancia trentalg@aston.ac.uk
|
|||||||
H. Merijn Brand h.m.brand@hccnet.nl
|
H. Merijn Brand h.m.brand@hccnet.nl
|
||||||
Hans Åberg haberg-1@telia.com
|
Hans Åberg haberg-1@telia.com
|
||||||
Jan Nieuwenhuizen janneke@gnu.org
|
Jan Nieuwenhuizen janneke@gnu.org
|
||||||
|
Jannick thirdedition@gmx.net
|
||||||
Jerry Quinn jlquinn@optonline.net
|
Jerry Quinn jlquinn@optonline.net
|
||||||
Jesse Thilo jthilo@gnu.org
|
Jesse Thilo jthilo@gnu.org
|
||||||
Jim Kent jkent@arch.sel.sony.com
|
Jim Kent jkent@arch.sel.sony.com
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ m4_define([b4_symbol_action],
|
|||||||
[m4_dquote(b4_symbol([$1], [type]))]),
|
[m4_dquote(b4_symbol([$1], [type]))]),
|
||||||
[(*yylocationp)])dnl
|
[(*yylocationp)])dnl
|
||||||
b4_symbol_case_([$1])[]dnl
|
b4_symbol_case_([$1])[]dnl
|
||||||
b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
|
b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
|
||||||
b4_symbol([$1], [$2])
|
b4_symbol([$1], [$2])
|
||||||
b4_syncline([@oline@], [@ofile@])
|
b4_syncline([@oline@], [@ofile@])
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ b4_dollar_pushdef([yysym.value],
|
|||||||
[m4_dquote(b4_symbol([$1], [type]))]),
|
[m4_dquote(b4_symbol([$1], [type]))]),
|
||||||
[yysym.location])dnl
|
[yysym.location])dnl
|
||||||
b4_symbol_case_([$1])
|
b4_symbol_case_([$1])
|
||||||
b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
|
b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
|
||||||
b4_symbol([$1], [$2])
|
b4_symbol([$1], [$2])
|
||||||
b4_syncline([@oline@], [@ofile@])
|
b4_syncline([@oline@], [@ofile@])
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ prepare_symbol_definitions (void)
|
|||||||
if (p->code)
|
if (p->code)
|
||||||
{
|
{
|
||||||
SET_KEY2 (pname, "file");
|
SET_KEY2 (pname, "file");
|
||||||
MUSCLE_INSERT_STRING (key, p->location.start.file);
|
MUSCLE_INSERT_C_STRING (key, p->location.start.file);
|
||||||
|
|
||||||
SET_KEY2 (pname, "line");
|
SET_KEY2 (pname, "line");
|
||||||
MUSCLE_INSERT_INT (key, p->location.start.line);
|
MUSCLE_INSERT_INT (key, p->location.start.line);
|
||||||
|
|||||||
@@ -329,6 +329,97 @@ exp: '0';
|
|||||||
[input.y:2: #error "2"
|
[input.y:2: #error "2"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
## ---------------------- ##
|
||||||
|
## %destructor syncline. ##
|
||||||
|
## ---------------------- ##
|
||||||
|
|
||||||
|
AT_TEST([%destructor syncline],
|
||||||
|
[[%destructor {
|
||||||
|
#error "2"
|
||||||
|
} <ival>
|
||||||
|
%{
|
||||||
|
]AT_YYERROR_DECLARE_EXTERN[
|
||||||
|
]AT_YYLEX_DECLARE_EXTERN[
|
||||||
|
%}
|
||||||
|
%union {
|
||||||
|
int ival;
|
||||||
|
}
|
||||||
|
%nterm <ival> exp
|
||||||
|
%%
|
||||||
|
exp: '0' { $$ = 0; };
|
||||||
|
%%
|
||||||
|
]],
|
||||||
|
[input.y:2: #error "2"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
## ------------------- ##
|
||||||
|
## %printer syncline. ##
|
||||||
|
## ------------------- ##
|
||||||
|
|
||||||
|
AT_TEST([%printer syncline],
|
||||||
|
[[%printer {
|
||||||
|
#error "2"
|
||||||
|
} <ival>
|
||||||
|
%debug
|
||||||
|
%code {
|
||||||
|
]AT_YYERROR_DECLARE_EXTERN[
|
||||||
|
]AT_YYLEX_DECLARE_EXTERN[
|
||||||
|
}
|
||||||
|
%union {
|
||||||
|
int ival;
|
||||||
|
}
|
||||||
|
%nterm <ival> exp
|
||||||
|
%%
|
||||||
|
exp: '0' { $$ = 0; };
|
||||||
|
%%
|
||||||
|
]],
|
||||||
|
[input.y:2: #error "2"
|
||||||
|
])
|
||||||
|
|
||||||
|
m4_popdef([AT_TEST])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## ------------------ ##
|
||||||
|
## syncline escapes. ##
|
||||||
|
## ------------------ ##
|
||||||
|
|
||||||
|
# AT_TEST([SKELETON])
|
||||||
|
# -------------------
|
||||||
|
m4_pushdef([AT_TEST],
|
||||||
|
[AT_SETUP([syncline escapes: $1])
|
||||||
|
|
||||||
|
AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
|
||||||
|
AT_DATA_GRAMMAR([\"\\\"\".y],
|
||||||
|
[[%skeleton "$1"
|
||||||
|
%code {
|
||||||
|
]AT_YYERROR_DECLARE[
|
||||||
|
]AT_YYLEX_DECLARE[
|
||||||
|
}
|
||||||
|
%destructor {} <>
|
||||||
|
%printer {} <>
|
||||||
|
%%
|
||||||
|
exp: '0'
|
||||||
|
%%
|
||||||
|
]AT_YYERROR_DEFINE[
|
||||||
|
]AT_YYLEX_DEFINE[
|
||||||
|
]AT_MAIN_DEFINE[
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_FULL_COMPILE([\"\\\"\"])
|
||||||
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
])
|
||||||
|
|
||||||
|
AT_TEST([yacc.c])
|
||||||
|
AT_TEST([glr.c])
|
||||||
|
AT_TEST([lalr1.cc])
|
||||||
|
AT_TEST([glr.cc])
|
||||||
|
|
||||||
|
m4_popdef([AT_TEST])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ----------- ##
|
## ----------- ##
|
||||||
|
|||||||
Reference in New Issue
Block a user