[PATCH] PR123012 Silent acceptance of unquoted character items in namelist input

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
The attached patch adds a check which detects the missing quote in a namelist 
read of a character string.  The problem occurs only when the string is digits 
only when looking for a possible repeat count.

Regression tested on x86_64-linux-gnu.

OK for mainline?

Regards,

Jerry

Author: Jerry DeLisle <[email protected]>
Date:   Wed Jan 7 21:48:49 2026 -0800

     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.
pr123012.diff (text/x-patch, 1.8 KB)
commit cd35da9d630b8d9420a8c6335bdee05901494465
Author: Jerry DeLisle <[email protected]>
Date:   Wed Jan 7 21:48:49 2026 -0800

    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!  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.