summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-02 17:36:23 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-02 17:36:23 -0400
commitd9bbb97bd0b8214d9f072b79858f030da3b43eff (patch)
tree1c83a8c3b2de8de3ba0d4cc88c4fd69b817ac609 /divelist.c
parent6b9aea1b96dce089aeff5570527f65a83ea2a190 (diff)
downloadsubsurface-d9bbb97bd0b8214d9f072b79858f030da3b43eff.tar.gz
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>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c3
1 files changed, 3 insertions, 0 deletions
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;