summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-26 16:57:12 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-26 19:44:01 -0800
commit720d4c65e854dceaedafd4d435a1832b75633d84 (patch)
tree8f20f55d5dd95222e22d739cfa8efff4da596135
parente726c9d65c7d1f1b8dbe238819b4d2847b8a058d (diff)
downloadsubsurface-720d4c65e854dceaedafd4d435a1832b75633d84.tar.gz
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>
-rw-r--r--divelist.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/divelist.c b/divelist.c
index 16e0eaf3e..08246738f 100644
--- a/divelist.c
+++ b/divelist.c
@@ -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 */