changeset 15346:bd906ac220b6

avoid GUI crash due to null pointer dereference * workspace-model.cc (workspace_model::parent): Don't dereference null pointers.
author John W. Eaton <jwe@octave.org>
date Mon, 10 Sep 2012 18:02:11 -0400
parents cd499f25f7be
children 6bdf379592d9
files libgui/src/workspace-model.cc
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/workspace-model.cc
+++ b/libgui/src/workspace-model.cc
@@ -144,12 +144,18 @@
     return QModelIndex();
 
   tree_item *childItem = static_cast<tree_item*>(index.internalPointer());
-  tree_item *parentItem = childItem->parent();
+
+  if (childItem)
+    {
+      tree_item *parentItem = childItem->parent();
 
-  if (parentItem == _rootItem)
-    return QModelIndex();
+      if (! parentItem || parentItem == _rootItem)
+        return QModelIndex();
 
-  return createIndex(parentItem->row(), 0, parentItem);
+      return createIndex(parentItem->row(), 0, parentItem);
+    }
+  else
+    return QModelIndex ();
 }
 
 int