diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-03-01 23:13:17 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-03-02 19:23:27 +0100 |
commit | 12463f1ecbcb30b39b8212454a6e598645123305 (patch) | |
tree | bf2f0be010efb094ae4ecd45078c6414d7c64c14 /gcc/fortran | |
parent | 38c1731193fe12d951f3010880406505507d90c1 (diff) | |
download | gcc-12463f1ecbcb30b39b8212454a6e598645123305.zip gcc-12463f1ecbcb30b39b8212454a6e598645123305.tar.gz gcc-12463f1ecbcb30b39b8212454a6e598645123305.tar.bz2 |
Fortran: error recovery after invalid assumed type declaration
gcc/fortran/ChangeLog:
PR fortran/104573
* resolve.cc (resolve_structure_cons): Avoid NULL pointer
dereference when there is no valid component.
gcc/testsuite/ChangeLog:
PR fortran/104573
* gfortran.dg/assumed_type_14.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/resolve.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 753aa27..0afa5d3 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -1288,15 +1288,19 @@ resolve_structure_cons (gfc_expr *expr, int init) } } - cons = gfc_constructor_first (expr->value.constructor); - /* A constructor may have references if it is the result of substituting a parameter variable. In this case we just pull out the component we want. */ if (expr->ref) comp = expr->ref->u.c.sym->components; - else + else if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS + || expr->ts.type == BT_UNION) + && expr->ts.u.derived) comp = expr->ts.u.derived->components; + else + return false; + + cons = gfc_constructor_first (expr->value.constructor); for (; comp && cons; comp = comp->next, cons = gfc_constructor_next (cons)) { |