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

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

Reply via email to