diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-09-15 18:32:15 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-09-17 21:03:30 -0400 |
commit | 421366d0fb52db317276ec404adb0c45cf398f29 (patch) | |
tree | 2ac96c86bf2ddc0ff37305081b84b42dc0b31a84 | |
parent | 0d637c2fa915d13af8e00d5f236d3f111101c6e3 (diff) | |
download | subsurface-421366d0fb52db317276ec404adb0c45cf398f29.tar.gz |
Correctly deal with empty XML files
Previously we could end up with a bogus dive with all zero data in it.
Adding dives/test24.xml to be able to test that we handle this case
correctly.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dives/test24.xml | 4 | ||||
-rw-r--r-- | parse-xml.c | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/dives/test24.xml b/dives/test24.xml new file mode 100644 index 000000000..8ddc9be42 --- /dev/null +++ b/dives/test24.xml @@ -0,0 +1,4 @@ +<dives> +<program name='subsurface' version='1'></program> +</dives> +<!-- intentionally empty dive file - should register as no dives --> diff --git a/parse-xml.c b/parse-xml.c index a4ae81b25..f47ac5a26 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -1173,11 +1173,23 @@ static void try_to_fill_trip(struct dive **divep, const char *name, char *buf) } /* - * File boundaries are dive boundaries. But sometimes there are + * While in some formats file boundaries are dive boundaries, in many + * others (as for example in our native format) there are * multiple dives per file, so there can be other events too that * trigger a "new dive" marker and you may get some nesting due * to that. Just ignore nesting levels. + * On the flipside it is possible that we start an XML file that ends + * up having no dives in it at all - don't create a bogus empty dive + * for those. It's not entirely clear what is the minimum set of data + * to make a dive valid, but if it has no location, no date and no + * samples I'm pretty sure it's useless. */ +static gboolean is_dive(void) +{ + return (cur_dive && + (cur_dive->location || cur_dive->when || cur_dive->samples)); +} + static void dive_start(void) { if (cur_dive) @@ -1188,7 +1200,7 @@ static void dive_start(void) static void dive_end(void) { - if (!cur_dive) + if (!is_dive()) return; record_dive(cur_dive); cur_dive = NULL; |