mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
c3274b0b9f
commit
e4a9787c5e
1 changed files with 5 additions and 2 deletions
|
@ -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)
|
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) {
|
while (nr-- > 0) {
|
||||||
dc = dc->next;
|
dc = dc->next;
|
||||||
|
@ -941,7 +944,7 @@ static inline struct gasmix *get_gasmix(struct dive *dive, struct divecomputer *
|
||||||
if (!gasmix) {
|
if (!gasmix) {
|
||||||
int cyl = explicit_first_cylinder(dive, dc);
|
int cyl = explicit_first_cylinder(dive, dc);
|
||||||
gasmix = &dive->cylinder[cyl].gasmix;
|
gasmix = &dive->cylinder[cyl].gasmix;
|
||||||
ev = dc->events;
|
ev = dc ? dc->events : NULL;
|
||||||
}
|
}
|
||||||
while (ev && ev->time.seconds < (unsigned int)time) {
|
while (ev && ev->time.seconds < (unsigned int)time) {
|
||||||
gasmix = get_gasmix_from_event(dive, ev);
|
gasmix = get_gasmix_from_event(dive, ev);
|
||||||
|
|
Loading…
Add table
Reference in a new issue