public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-2382] Fortran: avoid NULL pointer dereference on invalid DATA constant [PR99349]
Date: Fri,  2 Sep 2022 19:12:07 +0000 (GMT)	[thread overview]
Message-ID: <20220902191207.B032C3858D1E@sourceware.org> (raw)

https://gcc.gnu.org/g:b6aa7d45b502c01f8703c8d2cee2690f9aa8e282

commit r13-2382-gb6aa7d45b502c01f8703c8d2cee2690f9aa8e282
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Sep 2 21:07:26 2022 +0200

    Fortran: avoid NULL pointer dereference on invalid DATA constant [PR99349]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/99349
            * decl.cc (match_data_constant): Avoid NULL pointer dereference.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/99349
            * gfortran.dg/pr99349.f90: New test.
    
    Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>

Diff:
---
 gcc/fortran/decl.cc                   | 3 ++-
 gcc/testsuite/gfortran.dg/pr99349.f90 | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b6400514731..0f9b2ced4c2 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -423,7 +423,8 @@ match_data_constant (gfc_expr **result)
 	 data-pointer-initialization compatible (7.5.4.6) with the initial
 	 data target; the data statement object is initially associated
 	 with the target.  */
-      if ((*result)->symtree->n.sym->attr.save
+      if ((*result)->symtree
+	  && (*result)->symtree->n.sym->attr.save
 	  && (*result)->symtree->n.sym->attr.target)
 	return m;
       gfc_free_expr (*result);
diff --git a/gcc/testsuite/gfortran.dg/pr99349.f90 b/gcc/testsuite/gfortran.dg/pr99349.f90
new file mode 100644
index 00000000000..e1f4628af0b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr99349.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/99349 - ICE in match_data_constant
+! Contributed by G.Steinmetz
+
+function f()
+  logical, parameter :: a((1.)/0) = .true. ! { dg-error "Parameter array" }
+  integer :: b
+  data b /a%kind/ ! { dg-error "Syntax error" }
+end

                 reply	other threads:[~2022-09-02 19:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220902191207.B032C3858D1E@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@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).