When deleting dives make sure that amount_selected stays consistent

This could cause a crash if deleting the last dive and manually adding a
new one.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-09-18 19:37:03 -04:00
parent f83625efa5
commit f73e5b7268

View file

@ -1754,13 +1754,16 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
dive_table.nr--;
free(dive);
dive_list_update_dives();
/* now make sure the same dives stay selected and if necessary their trips are expanded */
/* now make sure the same dives stay selected and if necessary their trips are expanded
* also make sure that amount_selected stays consistent */
amount_selected = 0;
for_each_dive(i, dive) {
if (dive->selected) {
GtkTreePath *path = get_path_from(dive);
if (MODEL(dive_list) == TREEMODEL(dive_list))
gtk_tree_view_expand_to_path(tree_view, path);
gtk_tree_selection_select_path(selection, path);
amount_selected++;
}
}
mark_divelist_changed(TRUE);