From d9bbb97bd0b8214d9f072b79858f030da3b43eff Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 2 Oct 2015 17:36:23 -0400 Subject: 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 --- divelist.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/divelist.c b/divelist.c index 3cc0d2c8d..86117422f 100644 --- a/divelist.c +++ b/divelist.c @@ -833,6 +833,9 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b) id = a->id; i = get_divenr(a); 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); if (!res) return NULL; -- cgit v1.2.3-70-g09d2