aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-10-20 04:22:32 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-19 22:03:51 -0400
commite4a9787c5e6efb408dfb8280f51925e5a512b7d6 (patch)
tree5428943a9dbbd292fc414b6162ef688a14d36d72 /core
parentc3274b0b9ff9cb3827ac867b0aaec545ebaa29a8 (diff)
downloadsubsurface-e4a9787c5e6efb408dfb8280f51925e5a512b7d6.tar.gz
dive.h: add handling of NULL in get_dive_dc()
This line: dc = &dive->dc can SIGSEGV for a NULL 'dive' pointer. return NULL if 'dive' is NULL. Also handle NULL 'dc' in get_gasmix() and set 'ev' to NULL. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/dive.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/core/dive.h b/core/dive.h
index b02ce5f6c..64dee5196 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -608,7 +608,10 @@ static inline unsigned int number_of_computers(struct dive *dive)
static inline struct divecomputer *get_dive_dc(struct dive *dive, int nr)
{
- struct divecomputer *dc = &dive->dc;
+ struct divecomputer *dc;
+ if (!dive)
+ return NULL;
+ dc = &dive->dc;
while (nr-- > 0) {
dc = dc->next;
@@ -941,7 +944,7 @@ static inline struct gasmix *get_gasmix(struct dive *dive, struct divecomputer *
if (!gasmix) {
int cyl = explicit_first_cylinder(dive, dc);
gasmix = &dive->cylinder[cyl].gasmix;
- ev = dc->events;
+ ev = dc ? dc->events : NULL;
}
while (ev && ev->time.seconds < (unsigned int)time) {
gasmix = get_gasmix_from_event(dive, ev);