From: Paul Thomas Date: Fri, 26 Sep 2025 06:30:07 +0000 (+0100) Subject: Fortran: Fix uninitialized reads for pdt_13.f03 etc. [PR122002] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=947b22d9d0622f4a1bf7476f76f17b0d48201c4e;p=thirdparty%2Fgcc.git Fortran: Fix uninitialized reads for pdt_13.f03 etc. [PR122002] 2025-09-26 Harald Anlauf 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. --- diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 102c6a8e8df..a891dc86eae 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -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); diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 638018bcce3..fd03ceace51 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -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);