From d46b3db4bd016a3eccfb933c81c7a9d87c0ad403 Mon Sep 17 00:00:00 2001 From: Jerry DeLisle <jvdelisle@gcc.gnu.org> Date: Sun, 7 May 2023 18:54:55 -0700 Subject: [PATCH] Fortran: Reject semicolon after namelist name. PR fortran/109662 libgfortran/ChangeLog: * io/list_read.c: Add check for a semicolon after a namelist name in read input. Issue a runtime error message. gcc/testsuite/ChangeLog: * gfortran.dg/pr109662-a.f90: New test. --- gcc/testsuite/gfortran.dg/pr109662-a.f90 | 15 +++++++++++++++ libgfortran/io/list_read.c | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr109662-a.f90 diff --git a/gcc/testsuite/gfortran.dg/pr109662-a.f90 b/gcc/testsuite/gfortran.dg/pr109662-a.f90 new file mode 100644 index 000000000000..0059df28b9f3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr109662-a.f90 @@ -0,0 +1,15 @@ +! { dg-do run } +! { dg-options "-std=f2003" } +! PR109662-a semi-colon 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 78bfd9e87875..db3330060ce1 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -3598,9 +3598,9 @@ find_nml_name: /* 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)) + if ((c == ',' && !(compile_options.allow_std & GFC_STD_GNU)) || c == ';') generate_error (&dtp->common, LIBERROR_READ_VALUE, - "Comma after namelist name not allowed"); + "Non blank after namelist name not allowed"); if (!is_separator(c) && c != '!') { -- GitLab