mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Fix potential crash with old XML files
A file with no divecomputer section in a dive can trigger a SEGV as cur_dc could be NULL. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
edfdef1bbc
commit
62c4ec20c7
1 changed files with 10 additions and 10 deletions
20
parse-xml.c
20
parse-xml.c
|
@ -648,6 +648,15 @@ static void try_to_fill_event(const char *name, char *buf)
|
||||||
nonmatch("event", name, buf);
|
nonmatch("event", name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we don't have an explicit dive computer,
|
||||||
|
* we use the implicit one that every dive has..
|
||||||
|
*/
|
||||||
|
static struct divecomputer *get_dc(void)
|
||||||
|
{
|
||||||
|
return cur_dc ? : &cur_dive->dc;
|
||||||
|
}
|
||||||
|
|
||||||
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
|
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
|
||||||
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
|
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
|
||||||
{
|
{
|
||||||
|
@ -690,7 +699,7 @@ static void get_cylinderindex(char *buffer, void *_i)
|
||||||
int *i = _i;
|
int *i = _i;
|
||||||
*i = atoi(buffer);
|
*i = atoi(buffer);
|
||||||
if (lastcylinderindex != *i) {
|
if (lastcylinderindex != *i) {
|
||||||
add_gas_switch_event(cur_dive, cur_dc, cur_sample->time.seconds, *i);
|
add_gas_switch_event(cur_dive, get_dc(), cur_sample->time.seconds, *i);
|
||||||
lastcylinderindex = *i;
|
lastcylinderindex = *i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1159,15 +1168,6 @@ static void event_start(void)
|
||||||
cur_event.active = 1;
|
cur_event.active = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If we don't have an explicit dive computer,
|
|
||||||
* we use the implicit one that every dive has..
|
|
||||||
*/
|
|
||||||
static struct divecomputer *get_dc(void)
|
|
||||||
{
|
|
||||||
return cur_dc ? : &cur_dive->dc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void event_end(void)
|
static void event_end(void)
|
||||||
{
|
{
|
||||||
struct divecomputer *dc = get_dc();
|
struct divecomputer *dc = get_dc();
|
||||||
|
|
Loading…
Reference in a new issue