]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix possible null pointer dereference [PR124807]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 14 Apr 2026 18:53:15 +0000 (20:53 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 14 Apr 2026 18:53:15 +0000 (20:53 +0200)
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

index 6e48909c43a9e6590ba233854edc93c65ed6e60f..5d194635ad6f1780f9d1673274d2059bfe65aa2e 100644 (file)
@@ -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)
            {