]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix uninitialized reads for pdt_13.f03 etc. [PR122002]
authorPaul Thomas <pault@gcc.gnu.org>
Fri, 26 Sep 2025 06:30:07 +0000 (07:30 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Fri, 26 Sep 2025 06:30:07 +0000 (07:30 +0100)
2025-09-26  Harald Anlauf  <anlauf@gcc.gnu.org>

gcc/fortran
PR fortran/122002
* decl.cc (gfc_get_pdt_instance): Initialize 'instance' to NULL
and set 'kind_value' to zero before calling gfc_extract_int.
* primary.cc (gfc_match_rvalue): Intitialize 'ctr_arglist' to
NULL and test for default values if gfc_get_pdt_instance
returns NULL.

gcc/fortran/decl.cc
gcc/fortran/primary.cc

index 102c6a8e8df8dea18b497c74314d1125bb9afe5a..a891dc86eae9a98ce1f3e7a881f1473e76cd867c 100644 (file)
@@ -3857,7 +3857,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
   /* The symbol for the parameter in the template f2k_namespace.  */
   gfc_symbol *param;
   /* The hoped for instance of the PDT.  */
-  gfc_symbol *instance;
+  gfc_symbol *instance = NULL;
   /* The list of parameters appearing in the PDT declaration.  */
   gfc_formal_arglist *type_param_name_list;
   /* Used to store the parameter specification list during recursive calls.  */
@@ -4037,6 +4037,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
          goto error_return;
        }
 
+      kind_value = 0;
       gfc_extract_int (kind_expr, &kind_value);
       sprintf (name + strlen (name), "_%d", kind_value);
 
index 638018bcce37cd05fee7719b42596f99380f6eba..fd03ceace51fe18cfe087e8db92ac85b773f25f5 100644 (file)
@@ -4067,7 +4067,7 @@ gfc_match_rvalue (gfc_expr **result)
        {
          gfc_symtree *pdt_st;
          gfc_symbol *pdt_sym;
-         gfc_actual_arglist *ctr_arglist, *tmp;
+         gfc_actual_arglist *ctr_arglist = NULL, *tmp;
          gfc_component *c;
 
          /* Obtain the template.  */
@@ -4088,7 +4088,7 @@ gfc_match_rvalue (gfc_expr **result)
                 first argument list and return the parameter list in
                 ctr_arglist.  */
              m = gfc_get_pdt_instance (actual_arglist, &pdt_sym, &ctr_arglist);
-             if (m != MATCH_YES)
+             if (m != MATCH_YES || !ctr_arglist)
                {
                  if (ctr_arglist)
                    gfc_free_actual_arglist (ctr_arglist);