This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, libfortran] PR33039 Read NAMELIST: reads wrong namelist name


:REVIEWMAIL:

Jerry,

This one is obviously OK.

Thanks

Paul
:ADDPATCH fortran:

Hi,

This patch fixes this by checking for the required space after a namelist name. I also allow end of line characters, mostly to avoid rewriting a bunch of test cases. It seems reasonable. The space is a requirement on the user, not the compiler.

I will commit as obvious. Regression tested on x86-64-Gnu-Linux.

Attached is one test case that requires updating, plus one new test case.

Regards,

Jerry

2007-08-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>

    PR libfortran/33039
    * io/list_read.c (find_nml_name): Check for a space after a namelist
    name match.
------------------------------------------------------------------------

Index: list_read.c
===================================================================
--- list_read.c (revision 127265)
+++ list_read.c (working copy)
@@ -2593,6 +2593,14 @@ find_nml_name:
if (dtp->u.p.nml_read_error)
goto find_nml_name;
+ /* A trailing space is required, we give a little lattitude here, 10.9.1. */ + c = next_char (dtp);
+ if (!(c == ' ' || c == '\r' || c == '\n'))
+ {
+ unget_char (dtp, c);
+ goto find_nml_name;
+ }
+
/* Ready to read namelist objects. If there is an error in input
from stdin, output the error message and continue. */
------------------------------------------------------------------------


! { dg-do run }
! PR33039 Read NAMELIST:  reads wrong namelist name
! Test case from PR modified by Jerry DeLisle <jvdelisle@gcc.gnu.org>
PROGRAM namelist
CHARACTER*25 CHAR
NAMELIST /CODE/ CHAR, X
NAMELIST /CODEtwo/ X

OPEN(10, status="scratch")
write(10,'(a)') "File with test NAMELIST inputs"
write(10,'(a)') " &CODVJS char='VJS-Not a proper nml name', X=-0.5/"
write(10,'(a)') " &CODEone char='CODEone input', X=-1.0 /"
write(10,'(a)') " &CODEtwo char='CODEtwo inputs', X=-2.0/"
write(10,'(a)') " &code char='Lower case name',X=-3.0/"
write(10,'(a)') " &CODE char='Desired namelist sel', X=44./"
write(10,'(a)') " &CODEx char='Should not read CODEx nml', X=-5./"
write(10,'(a)') " $CODE char='Second desired nml', X=66.0 /"
write(10,'(a)') " $CODE X=77.0, char='Reordered desired nml'/"
rewind(10)
CHAR = 'Initialize string ***'
X = -777.
READ(10, nml=CODE, END=999)
if (x.ne.-3.0) call abort
READ(10, nml=CODE, END=999)
if (x.ne.44.0) call abort
READ(10, nml=CODE, END=999)
if (x.ne.66.0) call abort
READ(10, nml=CODE, END=999)
999 if (x.ne.77.0) call abort
END PROGRAM namelist
------------------------------------------------------------------------


! { dg-do run }
! PR17286
! Namelist read failed when spaces exist between the '=' and the numbers
! This is a libgfortran bug
! Derived from testcase provided by Paul Thomas <paulthomas2@wanadoo.fr>
program bug3
integer num1 , num2 , num3 , num4 data num3 / 42 /
data num4 / 56 /
namelist /mynml1/ num1,num2
namelist /mynml2/ num3,num4
logical dbg
data dbg / .FALSE. /
open(unit=10,status='SCRATCH')
write(10,'(A)') "&mynml1 ,num1= 16,num2=32,&end"
!
! write mynml2
!
write(10,mynml2)
rewind(10)
!
! now read back
!
num1 = -1
num2 = -1
read(10,mynml1)
if (num1.eq.16.and.num2.eq.32) then
if (dbg) write(*,mynml1)
else
if (dbg) print *, 'expected 16 32 got ',num1,num2
call abort
endif
num3 = -1
num4 = -1
read(10,mynml2)
if (num3.eq.42.and.num4.eq.56) then
if (dbg) write(*,mynml2)
else
if (dbg) print *, 'expected 42 56 got ',num3,num4
call abort
endif


close(10)
end



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]