From 04529aba93eae54302ff3f76fc3af987bc28df2e Mon Sep 17 00:00:00 2001
From: Tobias Burnus <burnus@net-b.de>
Date: Wed, 5 Sep 2012 18:40:48 +0200
Subject: [PATCH] re PR fortran/54462 (Another "segmentation fault" after an
 error in COMMON statement after r190853)

2012-09-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/54462
        * symbol.c (gfc_undo_symbols): Avoid NULL pointer dereference.

From-SVN: r190989
---
 gcc/fortran/ChangeLog |  5 +++++
 gcc/fortran/symbol.c  | 10 ++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index dbafc449cc9c..69c0fe8e5e67 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-05  Tobias Burnus  <burnus@net-b.de>
+
+	PR fortran/54462
+	* symbol.c (gfc_undo_symbols): Avoid NULL pointer dereference.
+
 2012-09-04  Janus Weil  <janus@gcc.gnu.org>
 
 	PR fortran/54435
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 8d3b56c95695..1f4a73526865 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -2919,10 +2919,12 @@ gfc_undo_symbols (void)
 		  gfc_symtree st, *st0;
 		  st0 = find_common_symtree (p->ns->common_root,
 					     p->common_block);
-
-		  st.name = st0->name;
-		  gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
-		  free (st0);
+		  if (st0)
+		    {
+		      st.name = st0->name;
+		      gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
+		      free (st0);
+		    }
 		}
 
 	      if (p->common_block->head == p)
-- 
GitLab