summaryrefslogtreecommitdiffstats
path: root/core/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-27 16:29:22 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-28 05:44:33 -0700
commitfd9e1d6a8aacddab380fd8ea099ebba90169c749 (patch)
treec47b74f1f573494b8ef5b6b0645e21dd368b6a88 /core/divelist.c
parent130534aedfb7c9b48cceae5aca5a7c82f2444571 (diff)
downloadsubsurface-fd9e1d6a8aacddab380fd8ea099ebba90169c749.tar.gz
Cleanup: avoid dereferencing NULL
We should call this function with two well defined dive_or_trip structures which means that exactly one of the two values is set in each argument. But in order to not have bugs elsewhere leed to crashes here, be more tolerant of malformed argumnts. Fixes CID 350100 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/divelist.c')
-rw-r--r--core/divelist.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 3c0570673..de9509471 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -1478,6 +1478,18 @@ static int comp_dive_to_trip(struct dive *a, struct dive_trip *b)
static int comp_dive_or_trip(struct dive_or_trip a, struct dive_or_trip b)
{
+ /* we should only be called with both a and b having exactly one of
+ * dive or trip not NULL. But in an abundance of caution, make sure
+ * we still give a consistent answer even when called with invalid
+ * arguments, as otherwise we might be hunting down crashes at a later
+ * time...
+ */
+ if (!a.dive && !a.trip && !b.dive && !b.trip)
+ return 0;
+ if (!a.dive && !a.trip)
+ return -1;
+ if (!b.dive && !b.trip)
+ return 1;
if (a.dive && b.dive)
return comp_dives(a.dive, b.dive);
if (a.trip && b.trip)