diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2019-10-27 07:28:57 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-10-27 07:35:46 -0700 |
commit | 33137c62b05006bb2bf3925b1e504a95f356830e (patch) | |
tree | 27267df8553a21a74eb9ed0655189f872037d83a /core/dive.c | |
parent | 08fcda60ac9a5705fa84b79cabe189a9e850e31d (diff) | |
download | subsurface-33137c62b05006bb2bf3925b1e504a95f356830e.tar.gz |
Cleanup: NULL check pointer before dereferencing
Found by Coverity. CID 350081, 350087, 350095
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/dive.c b/core/dive.c index 20981c48c..d845d8077 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3275,11 +3275,12 @@ int split_dive(const struct dive *dive, struct dive **new1, struct dive **new2) int split_dive_at_time(const struct dive *dive, duration_t time, struct dive **new1, struct dive **new2) { int i = 0; - struct sample *sample = dive->dc.sample; - *new1 = *new2 = NULL; if (!dive) return -1; + + struct sample *sample = dive->dc.sample; + *new1 = *new2 = NULL; while(sample->time.seconds < time.seconds) { ++sample; ++i; @@ -3670,7 +3671,7 @@ static void delete_divecomputer(struct dive *d, int num) struct divecomputer *pdc = &d->dc; for (i = 0; i < num - 1 && pdc; i++) pdc = pdc->next; - if (pdc->next) { + if (pdc && pdc->next) { struct divecomputer *dc = pdc->next; pdc->next = dc->next; free_dc(dc); |