]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: [PR123012] Silent acceptance of unquoted character items
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 8 Jan 2026 05:48:49 +0000 (21:48 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 11 Jan 2026 03:59:56 +0000 (19:59 -0800)
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.

gcc/testsuite/gfortran.dg/namelist_100.f90 [new file with mode: 0644]
libgfortran/io/list_read.c

diff --git a/gcc/testsuite/gfortran.dg/namelist_100.f90 b/gcc/testsuite/gfortran.dg/namelist_100.f90
new file mode 100644 (file)
index 0000000..483cf9f
--- /dev/null
@@ -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
index ccce4e44a4f3fdaa648b0d34419118fde2b60538..2aadc8f4d3c1bf3bf37b3390f038429a450a5467 100644 (file)
@@ -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!  */