public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jerry D <jvdelisle2@gmail.com>
To: gfortran <fortran@gcc.gnu.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [patch, fortran] PR109662 Namelist input with comma after name accepted
Date: Fri, 5 May 2023 20:41:48 -0700	[thread overview]
Message-ID: <e1dbf978-ac53-8f2d-4db5-b153300abad3@gmail.com> (raw)

[-- 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);

             reply	other threads:[~2023-05-06  3:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-06  3:41 Jerry D [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1dbf978-ac53-8f2d-4db5-b153300abad3@gmail.com \
    --to=jvdelisle2@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).