comparison libgui/src/workspace-model.cc @ 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 501a9cc2c68f
comparison
equal deleted inserted replaced
15345:cd499f25f7be 15346:bd906ac220b6
142 { 142 {
143 if (!index.isValid()) 143 if (!index.isValid())
144 return QModelIndex(); 144 return QModelIndex();
145 145
146 tree_item *childItem = static_cast<tree_item*>(index.internalPointer()); 146 tree_item *childItem = static_cast<tree_item*>(index.internalPointer());
147 tree_item *parentItem = childItem->parent(); 147
148 148 if (childItem)
149 if (parentItem == _rootItem) 149 {
150 return QModelIndex(); 150 tree_item *parentItem = childItem->parent();
151 151
152 return createIndex(parentItem->row(), 0, parentItem); 152 if (! parentItem || parentItem == _rootItem)
153 return QModelIndex();
154
155 return createIndex(parentItem->row(), 0, parentItem);
156 }
157 else
158 return QModelIndex ();
153 } 159 }
154 160
155 int 161 int
156 workspace_model::rowCount(const QModelIndex &parent) const 162 workspace_model::rowCount(const QModelIndex &parent) const
157 { 163 {