aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2023-05-05 20:12:25 -0700
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2023-05-06 07:23:11 -0700
commit96d699196285858df5d1484b4443cf849908662f (patch)
tree2f1ef2452caa1bf56cd682f3053efc4532531ec6
parentb7fe38c14e5f1bc32950c7b2ffc8537c7c381af4 (diff)
downloadgcc-96d699196285858df5d1484b4443cf849908662f.zip
gcc-96d699196285858df5d1484b4443cf849908662f.tar.gz
gcc-96d699196285858df5d1484b4443cf849908662f.tar.bz2
Fortran: Namelist read with invalid input accepted.
PR fortran/109662 libgfortran/ChangeLog: * io/list_read.c: Add a check for a comma after a namelist name in read input. Issue a runtime error message. gcc/testsuite/ChangeLog: * gfortran.dg/pr109662.f90: New test.
-rw-r--r--gcc/testsuite/gfortran.dg/pr109662.f9015
-rw-r--r--libgfortran/io/list_read.c6
2 files changed, 20 insertions, 1 deletions
diff --git a/gcc/testsuite/gfortran.dg/pr109662.f90 b/gcc/testsuite/gfortran.dg/pr109662.f90
new file mode 100644
index 0000000..988cfab
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr109662.f90
@@ -0,0 +1,15 @@
+! { dg-do run }
+! { dg-options "-std=f2003" }
+! PR109662 a comma after namelist name accepted on input.
+program testnmlread
+ implicit none
+ character(16) :: list = '&stuff, n = 759/'
+ character(100)::message
+ integer :: n, ioresult
+ namelist/stuff/n
+ message = ""
+ ioresult = 0
+ n = 99
+ read(list,nml=stuff,iostat=ioresult)
+ if (ioresult == 0) STOP 13
+end program testnmlread
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 109313c..78bfd9e 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -3596,8 +3596,12 @@ find_nml_name:
if (dtp->u.p.nml_read_error)
goto find_nml_name;
- /* A trailing space is required, we give a little latitude here, 10.9.1. */
+ /* A trailing space is required, we allow a comma with std=gnu. */
c = next_char (dtp);
+ if (c == ',' && !(compile_options.allow_std & GFC_STD_GNU))
+ generate_error (&dtp->common, LIBERROR_READ_VALUE,
+ "Comma after namelist name not allowed");
+
if (!is_separator(c) && c != '!')
{
unget_char (dtp, c);