This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] [4.3 Regression] PR34291 Segfault in io/list_read.c handling of end conditions
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 30 Nov 2007 14:37:54 -0800
- Subject: [patch, libgfortran] [4.3 Regression] PR34291 Segfault in io/list_read.c handling of end conditions
I plan to commit the attached patch and test case under the obvious and simple rule.
Regression tested on x86-64.
Jerry
2007-11-30 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/34291
* io/list_read.c (read_character): When reading an unquoted string,
return if special characters that could signify the end of the namelist
read are encountered.
! { dg-do run }
! PR34291 Segfault on &end in namelist expanded read of character
implicit none
character(len=10), dimension(2) :: var
namelist /inx/ var
var = "goodbye"
open(unit=11, status='scratch')
write (11, *) "&inx"
write (11, *) "var(1)='hello'"
write (11, *) "&end"
rewind (11)
read(11,nml=inx)
if (var(1) /= 'hello' .and. var(2) /= 'goodbye') call abort
var = "goodbye"
rewind (11)
write (11, *) "$inx"
write (11, *) "var(1)='hello'"
write (11, *) "$end"
rewind (11)
read(11,nml=inx)
if (var(1) /= 'hello' .and. var(2) /= 'goodbye') call abort
end
Index: list_read.c
===================================================================
--- list_read.c (revision 130547)
+++ list_read.c (working copy)
@@ -896,7 +896,8 @@ read_character (st_parameter_dt *dtp, in
if (dtp->u.p.namelist_mode)
{
if (dtp->u.p.current_unit->flags.delim == DELIM_APOSTROPHE
- || dtp->u.p.current_unit->flags.delim == DELIM_QUOTE)
+ || dtp->u.p.current_unit->flags.delim == DELIM_QUOTE
+ || c == '&' || c == '$' || c == '/')
{
unget_char (dtp, c);
return;
@@ -923,8 +924,9 @@ read_character (st_parameter_dt *dtp, in
goto get_string;
}
}
-
+
l_push_char (dtp, c);
+
if (c == '=' || c == '(')
{
dtp->u.p.item_count = 0;
@@ -936,6 +938,7 @@ read_character (st_parameter_dt *dtp, in
/* The string is too long to be a valid object name so assume that it
is a string to be read in as a value. */
+ dtp->u.p.item_count = 0;
dtp->u.p.line_buffer_enabled = 1;
goto get_string;
}