public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] PR109662 Namelist input with comma after name accepted
@ 2023-05-06  3:41 Jerry D
  2023-05-06  4:02 ` Steve Kargl
  0 siblings, 1 reply; 9+ messages in thread
From: Jerry D @ 2023-05-06  3:41 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

The attached patch adds a check for the invalid comma and emits a 
runtime error if -std=f95,f2003,f2018 are specified at compile time.

Attached patch includes a new test case.

Regression tested on x86_64-linux-gnu.

OK for mainline?

Regards,

Jerry

Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Fri May 5 20:12:25 2023 -0700

     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.

[-- Attachment #2: mysubmit.diff --]
[-- Type: text/x-patch, Size: 1316 bytes --]

diff --git a/gcc/testsuite/gfortran.dg/pr109662.f90 b/gcc/testsuite/gfortran.dg/pr109662.f90
new file mode 100644
index 00000000000..988cfab73cc
--- /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 109313c15b1..78bfd9e8787 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);

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-12 20:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06  3:41 [patch, fortran] PR109662 Namelist input with comma after name accepted Jerry D
2023-05-06  4:02 ` Steve Kargl
2023-05-06 18:15   ` Harald Anlauf
2023-05-06 22:37     ` Jerry D
2023-05-07 17:33     ` Jerry D
2023-05-07 18:33       ` Harald Anlauf
2023-05-08  0:13         ` Steve Kargl
2023-05-08 19:03           ` Harald Anlauf
2023-05-12 20:36             ` Jerry D

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).