PR123012 Silent acceptance of unquoted character items in namelist input
Commit Message
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 <jvdelisle@gcc.gnu.org>
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.
Comments
Committed before I forget.
commit 3e77ce5bcc4d9e467f119bbece5c26cdb4e24210 (HEAD -> master, origin/master,
origin/HEAD)
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
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.
On 1/7/26 10:12 PM, Jerry D wrote:
> 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 <jvdelisle@gcc.gnu.org>
> 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.
>
>
commit cd35da9d630b8d9420a8c6335bdee05901494465
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
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.
new file mode 100644
@@ -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
@@ -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! */