Fix crash when trip info changes across remember/restore tree state

Interesting crash. Importing a file gets us to a stage where we have a
trip tree note with a date that doesn't exist as trip date. That's clearly
bogus. And in import_files() we assume that all is still fine and try to
restore the old expanded / selected state for the various trips.

There is clearly a bigger issue here, this patch at least prevents the
actual crash from happening by making sure the pointer is non-NULL before
dereferencing it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-12-26 16:57:12 -08:00
parent e726c9d65c
commit 720d4c65e8

View file

@ -1995,18 +1995,20 @@ static gboolean restore_node_state(GtkTreeModel *model, GtkTreePath *path, GtkTr
int idx;
timestamp_t when;
struct dive *dive;
dive_trip_t *trip;
GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1);
if (idx < 0) {
if (find_trip_by_time(when)->expanded)
trip = find_trip_by_time(when);
if (trip && trip->expanded)
gtk_tree_view_expand_row(tree_view, path, FALSE);
if (find_trip_by_time(when)->selected)
if (trip && trip->selected)
gtk_tree_selection_select_iter(selection, iter);
} else {
dive = get_dive(idx);
if (dive->selected)
if (dive && dive->selected)
gtk_tree_selection_select_iter(selection, iter);
}
/* continue foreach */