Do not dereference NULL pointer in resolve_ref (PR fortran/89185).
authorMartin Liska <mliska@suse.cz>
Mon, 4 Feb 2019 13:28:34 +0000 (14:28 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 4 Feb 2019 13:28:34 +0000 (13:28 +0000)
2019-02-04  Martin Liska  <mliska@suse.cz>

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

gcc/fortran/ChangeLog
gcc/fortran/resolve.c

index c3b4a5c0ff6a1e546475981bbf6ae4e8c91db50b..1bd851a4b0e1adf53951b193e25d782052b0641e 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-04  Martin Liska  <mliska@suse.cz>
+
+       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  <mliska@suse.cz>
 
        PR fortran/88912
index 5e95777af550bf6f6bf9ce1b0c12e4aabba03c36..92d27fc7632a580a85aa58b6b5f1fc94de587e29 100644 (file)
@@ -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;
       }