From: Martin Liska Date: Mon, 4 Feb 2019 13:28:34 +0000 (+0100) Subject: Do not dereference NULL pointer in resolve_ref (PR fortran/89185). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a693d9b3d69d905d4270c9d1b9fe0bc8d19a932e;p=gcc.git Do not dereference NULL pointer in resolve_ref (PR fortran/89185). 2019-02-04 Martin Liska PR fortran/89185 * resolve.c (resolve_ref): Remove breakout variable as we need to prevent prev = &(*prev)->next to happen with *prev == NULL. From-SVN: r268521 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c3b4a5c0ff6..1bd851a4b0e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-02-04 Martin Liska + + PR fortran/89185 + * resolve.c (resolve_ref): Remove breakout variable as + we need to prevent prev = &(*prev)->next to happen + with *prev == NULL. + 2019-02-04 Martin Liska PR fortran/88912 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 5e95777af55..92d27fc7632 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5046,7 +5046,6 @@ resolve_ref (gfc_expr *expr) int current_part_dimension, n_components, seen_part_dimension; gfc_ref *ref, **prev; bool equal_length; - bool breakout; for (ref = expr->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY && ref->u.ar.as == NULL) @@ -5055,8 +5054,8 @@ resolve_ref (gfc_expr *expr) break; } - breakout = false; - for (prev = &expr->ref; !breakout && *prev != NULL; prev = &(*prev)->next) + for (prev = &expr->ref; *prev != NULL; + prev = *prev == NULL ? prev : &(*prev)->next) switch ((*prev)->type) { case REF_ARRAY: @@ -5082,8 +5081,6 @@ resolve_ref (gfc_expr *expr) expr->ts.u.cl = ref->u.ss.length; ref->u.ss.length = NULL; gfc_free_ref_list (ref); - if (*prev == NULL) - breakout = true; } break; }