Crash fix in add_single_dive. No writing to dive_table.dives[-1]

Signed-off-by: K. Heller <pestophagous@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
K. \"pestophagous\" Heller 2015-12-03 22:10:03 -08:00 committed by Dirk Hohndel
parent 2778470b97
commit 445dbe73bf

View file

@ -790,6 +790,9 @@ void add_single_dive(int idx, struct dive *dive)
dive_table.nr++;
if (dive->selected)
amount_selected++;
if (idx < 0)
// convert an idx of -1 so we do insert-at-end:
idx = dive_table.nr - 1;
for (i = idx; i < dive_table.nr; i++) {
struct dive *tmp = dive_table.dives[i];
dive_table.dives[i] = dive;