From: Jerry DeLisle Date: Thu, 8 Jan 2026 05:48:49 +0000 (-0800) Subject: Fortran: [PR123012] Silent acceptance of unquoted character items X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e77ce5bcc4d9e467f119bbece5c26cdb4e24210;p=thirdparty%2Fgcc.git Fortran: [PR123012] Silent acceptance of unquoted character items PR libfortran/123012 libgfortran/ChangeLog: * io/list_read.c (read_character): Add new check when no quate is provided and the character string is digits only. gcc/testsuite/ChangeLog: * gfortran.dg/namelist_100.f90: New test. --- diff --git a/gcc/testsuite/gfortran.dg/namelist_100.f90 b/gcc/testsuite/gfortran.dg/namelist_100.f90 new file mode 100644 index 00000000000..483cf9fae83 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/namelist_100.f90 @@ -0,0 +1,16 @@ +! { dg-do run ) +! { dg-shouldfail "Missing quote" } +program nml_quotes_bug + implicit none + integer :: unit = 10 + character(8) :: c1, c2 + namelist /tovs_obs_chan/ c1, c2 + open (unit ,file="nml-quotes-bug.nml") + write(unit,*) "&tovs_obs_chan" + write(unit,*) " c1 = '1'," + write(unit,*) " c2 = 2 ," + write(unit,*) "/" + rewind(unit) + read (unit ,nml=tovs_obs_chan) + close(unit ,status="delete") +end program nml_quotes_bug diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index ccce4e44a4f..2aadc8f4d3c 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -1314,6 +1314,12 @@ read_character (st_parameter_dt *dtp, int length __attribute__ ((unused))) CASE_SEPARATORS: case EOF: + if (dtp->u.p.namelist_mode) + { + snprintf (message, IOMSG_LEN, "Missing quote while reading item %d", + dtp->u.p.item_count); + generate_error (&dtp->common, LIBERROR_READ_VALUE, message); + } unget_char (dtp, c); goto done; /* String was only digits! */