Don't access undefined dive

When walking the dive table we need to stop before accessing the
yet-to-be-added new dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-03-03 13:16:28 -08:00
parent bf798390fa
commit 01ae4af13d

View file

@ -794,7 +794,7 @@ void add_single_dive(int idx, struct dive *dive)
if (idx < 0) {
// convert an idx of -1 so we do insert-in-chronological-order
idx = dive_table.nr - 1;
for (int i = 0; i < dive_table.nr; i++) {
for (int i = 0; i < dive_table.nr - 1; i++) {
if (dive->when <= dive_table.dives[i]->when) {
idx = i;
break;