diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-12-13 06:56:07 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-20 15:20:44 -0700 |
commit | 0d78fe45c31e2856a68d63235ad6acc8f50312f1 (patch) | |
tree | b81f2abb1300bba92a7025a08edb92ef4c83852d /core | |
parent | 8585f0698cd1e52ee46bd0d91c5918acf26f3001 (diff) | |
download | subsurface-0d78fe45c31e2856a68d63235ad6acc8f50312f1.tar.gz |
Core: consider invalid flag when adding dives
Adding dives uses the number of the last dive to create a new
dive number. Ignore invalid dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/core/divelist.c b/core/divelist.c index df28bba69..a16563310 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1268,6 +1268,16 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table * } } +static struct dive *get_last_valid_dive() +{ + int i; + for (i = dive_table.nr - 1; i >= 0; i--) { + if (!dive_table.dives[i]->invalid) + return dive_table.dives[i]; + } + return NULL; +} + /* return the number a dive gets when inserted at the given index. * this function is supposed to be called *before* a dive was added. * this returns: @@ -1277,13 +1287,10 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table * */ int get_dive_nr_at_idx(int idx) { - if (dive_table.nr == 0) + struct dive *last_dive = get_last_valid_dive(dive_table.nr - 1); + if (!last_dive) return 1; - if (idx >= dive_table.nr) { - struct dive *last_dive = get_dive(dive_table.nr - 1); - return last_dive->number ? last_dive->number + 1 : 0; - } - return 0; + return last_dive->number ? last_dive->number + 1 : 0; } void set_dive_nr_for_current_dive() |