diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 21:38:12 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-21 21:40:21 -0700 |
commit | 18d52ec86efcc4e42f2bad0fc47ac1a3d5b69435 (patch) | |
tree | c72fef659ae85c7408b2f520f1bdfb60c7f65227 /dive.c | |
parent | 52ee5f28c2f19ea386398436e446b23fb7a080ff (diff) | |
download | subsurface-18d52ec86efcc4e42f2bad0fc47ac1a3d5b69435.tar.gz |
Prevent possible null pointer dereference
Neither of these functions should ever be called with dc == NULL.
But it's easy to prevent the potential crash.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r-- | dive.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -728,6 +728,8 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me for (i = 0; i < MAX_CYLINDERS; i++) mean[i] = duration[i] = 0; + if (!dc) + return; struct event *ev = get_next_event(dc->events, "gaschange"); if (!ev || (dc && dc->sample && ev->time.seconds == dc->sample[0].time.seconds && get_next_event(ev->next, "gaschange") == NULL)) { // we have either no gas change or only one gas change and that's setting an explicit first cylinder @@ -861,13 +863,14 @@ static int same_rounded_pressure(pressure_t a, pressure_t b) * first cylinder - in which case cylinder 0 is indeed the first cylinder */ int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc) { - struct event *ev = get_next_event(dc->events, "gaschange"); - if (ev && dc && dc->sample && ev->time.seconds == dc->sample[0].time.seconds) - return get_cylinder_index(dive, ev); - else if (dc->divemode == CCR) - return MAX(get_cylinder_idx_by_use(dive, DILUENT), 0); - else - return 0; + if (dc) { + struct event *ev = get_next_event(dc->events, "gaschange"); + if (ev && dc->sample && ev->time.seconds == dc->sample[0].time.seconds) + return get_cylinder_index(dive, ev); + else if (dc->divemode == CCR) + return MAX(get_cylinder_idx_by_use(dive, DILUENT), 0); + } + return 0; } /* this gets called when the dive mode has changed (so OC vs. CC) |