aboutsummaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-18 10:39:25 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-18 10:39:25 -0800
commit62c4ec20c7c8395eb2d22011520b6fadc03a87a2 (patch)
treeaabee2abb204e0770ab7da48346884b53d8319b4 /parse-xml.c
parentedfdef1bbc173a489f7157c4078c4e2227a61ccb (diff)
downloadsubsurface-62c4ec20c7c8395eb2d22011520b6fadc03a87a2.tar.gz
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>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 87e4f8645..35ebf0446 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -648,6 +648,15 @@ static void try_to_fill_event(const char *name, char *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 */
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;
*i = atoi(buffer);
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;
}
}
@@ -1159,15 +1168,6 @@ static void event_start(void)
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)
{
struct divecomputer *dc = get_dc();