[PATCH, committed] Fortran: fix possible null pointer dereference [PR124807]

Harald Anlauf <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Dear all,

I pushed the attached obvious patch that fixes a potential null pointer
dereference (as seen by Coverity) as r16-8611-g29fba8b050b096 .

Thanks,
Harald
0001-Fortran-fix-possible-null-pointer-dereference-PR1248.patch (text/x-patch, 1.3 KB)
From 29fba8b050b09616a9397d8fc8ce9328457fdcc5 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <[email protected]>
Date: Tue, 14 Apr 2026 20:53:15 +0200
Subject: [PATCH] Fortran: fix possible null pointer dereference [PR124807]

	PR fortran/124807

gcc/fortran/ChangeLog:

	* decl.cc (add_init_expr_to_sym): Suggested by Coverity:
	Check sym->as != NULL before dereferencing it.
---
 gcc/fortran/decl.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 6e48909c43a..5d194635ad6 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2264,7 +2264,7 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus,
 
       /* If sym is implied-shape, set its upper bounds from init.  */
       if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
-	  && sym->as->type == AS_IMPLIED_SHAPE)
+	  && sym->as && sym->as->type == AS_IMPLIED_SHAPE)
 	{
 	  int dim;
 
@@ -2333,7 +2333,7 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus,
 
       /* Ensure that explicit bounds are simplified.  */
       if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
-	  && sym->as->type == AS_EXPLICIT)
+	  && sym->as && sym->as->type == AS_EXPLICIT)
 	{
 	  for (int dim = 0; dim < sym->as->rank; ++dim)
 	    {
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.