Prevent dive_from_path from dereferencing invalid iter

This fixes a bug that Lubomir reported in a different way from the patch
that he providede; I believe this to be more generic.

Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-09-18 19:13:59 -04:00
parent 7226a48a8c
commit 744b4e0c1c

View file

@ -166,9 +166,12 @@ static struct dive *dive_from_path(GtkTreePath *path)
GtkTreeIter iter;
int idx;
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
return get_dive(idx);
if (gtk_tree_model_get_iter(MODEL(dive_list), &iter, path)) {
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
return get_dive(idx);
} else {
return NULL;
}
}