Fix setting of the dive_table.preexisting logic

The 'preexisting' value is used for downloading dives: we want to add
new dives but, but then compare those new dives against the
preexisting ones before we start sorting things and possibly merging
them.

However, the value was only updated sporadically, resulting in it
having stale information in it.  Which would cause problems
particularly if you deleted dives, so that the preexisting value would
point past the actual existing values!

So just update it unconditionally in dive_list_update_dives(), which
anything that changes the dive list is supposed to call in order to
display the changes anyway.

Also, just for safety, when removing a dive, put NULL in the last dive
table location.  Nobody should ever access past the end anyway (this
is enforced by 'get_dive()') but there are places that access the dive
list table directly, and the libdivecomputer download was one of
those.  No reason to leave stale dive pointers possibly around for
uses like that.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2013-01-23 13:19:58 -08:00 committed by Dirk Hohndel
parent 413b9026dd
commit 4982389ca7
3 changed files with 3 additions and 3 deletions

View file

@ -1457,6 +1457,7 @@ static void fill_dive_list(void)
void dive_list_update_dives(void) void dive_list_update_dives(void)
{ {
dive_table.preexisting = dive_table.nr;
gtk_tree_store_clear(TREESTORE(dive_list)); gtk_tree_store_clear(TREESTORE(dive_list));
gtk_tree_store_clear(LISTSTORE(dive_list)); gtk_tree_store_clear(LISTSTORE(dive_list));
fill_dive_list(); fill_dive_list();
@ -2207,7 +2208,7 @@ void delete_single_dive(int idx)
remove_dive_from_trip(dive); remove_dive_from_trip(dive);
for (i = idx; i < dive_table.nr - 1; i++) for (i = idx; i < dive_table.nr - 1; i++)
dive_table.dives[i] = dive_table.dives[i+1]; dive_table.dives[i] = dive_table.dives[i+1];
dive_table.nr--; dive_table.dives[--dive_table.nr] = NULL;
if (dive->selected) if (dive->selected)
amount_selected--; amount_selected--;
/* free all allocations */ /* free all allocations */

View file

@ -242,7 +242,6 @@ static void file_close(GtkWidget *w, gpointer data)
/* free the dives and trips */ /* free the dives and trips */
while (dive_table.nr) while (dive_table.nr)
delete_single_dive(0); delete_single_dive(0);
dive_table.preexisting = 0;
mark_divelist_changed(FALSE); mark_divelist_changed(FALSE);
/* clear the selection and the statistics */ /* clear the selection and the statistics */

2
main.c
View file

@ -181,6 +181,7 @@ void report_dives(gboolean is_imported, gboolean prefer_imported)
add_single_dive(i, merged); add_single_dive(i, merged);
delete_single_dive(i+1); delete_single_dive(i+1);
delete_single_dive(i+1); delete_single_dive(i+1);
mark_divelist_changed(TRUE);
} }
/* make sure no dives are still marked as downloaded */ /* make sure no dives are still marked as downloaded */
for (i = 1; i < dive_table.nr; i++) for (i = 1; i < dive_table.nr; i++)
@ -195,7 +196,6 @@ void report_dives(gboolean is_imported, gboolean prefer_imported)
if (preexisting != dive_table.nr) if (preexisting != dive_table.nr)
mark_divelist_changed(TRUE); mark_divelist_changed(TRUE);
} }
dive_table.preexisting = dive_table.nr;
dive_list_update_dives(); dive_list_update_dives();
} }