mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
130534aedf
commit
fd9e1d6a8a
1 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue