Avoid working with invalid dive indices

When calling merge_two_dives both dives should be in the dive list so i
and j should never be -1. But just as extra precaution, bail if that's the
case (so that the helper functions below aren't called with negative
indices).

Coverity CID 1189514

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-10-02 17:36:23 -04:00
parent 6b9aea1b96
commit d9bbb97bd0

View file

@ -833,6 +833,9 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
id = a->id; id = a->id;
i = get_divenr(a); i = get_divenr(a);
j = get_divenr(b); j = get_divenr(b);
if (i < 0 || j < 0)
// something is wrong with those dives. Bail
return NULL;
res = merge_dives(a, b, b->when - a->when, false); res = merge_dives(a, b, b->when - a->when, false);
if (!res) if (!res)
return NULL; return NULL;