summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-08 12:29:06 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-08 12:29:06 -0700
commitf297d9f91e5919c180d15be9562b8e15e6dd368e (patch)
tree835c8cf943badd99daeca1ab53c10b3d59c0c3a8 /parse-xml.c
parentc054b18b7055473279b7120d334c453d1c0427ec (diff)
downloadsubsurface-f297d9f91e5919c180d15be9562b8e15e6dd368e.tar.gz
Fix picture loading
Signed vs unsigned comparisons are such a pain. Since we want offsets to be +/- 30 minutes around the dive we need to allow negative offsets - but duration_t was defined as uint32_t. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 3fb013d23..01599d61a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -412,6 +412,20 @@ static void sampletime(char *buffer, duration_t *time)
}
}
+static void offsettime(char *buffer, offset_t *time)
+{
+ duration_t uoffset;
+ int sign = 1;
+ if (*buffer == '-') {
+ sign = -1;
+ buffer++;
+ }
+ /* yes, this could indeed fail if we have an offset > 34yrs
+ * - too bad */
+ sampletime(buffer, &uoffset);
+ time->seconds = sign * uoffset.seconds;
+}
+
static void duration(char *buffer, duration_t *time)
{
/* DivingLog 5.08 (and maybe other versions) appear to sometimes
@@ -1106,7 +1120,7 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
if (MATCH("filename.picture", utf8_string, &cur_picture->filename))
return;
- if (MATCH("offset.picture", sampletime, &cur_picture->offset))
+ if (MATCH("offset.picture", offsettime, &cur_picture->offset))
return;
if (MATCH("gps.picture", gps_picture_location, cur_picture))
return;
@@ -1317,7 +1331,8 @@ static void event_end(void)
if (cur_event.type == 123) {
struct picture *pic = alloc_picture();
pic->filename = strdup(cur_event.name);
- pic->offset = cur_event.time;
+ /* theoretically this could fail - but we didn't support multi year offsets */
+ pic->offset.seconds = cur_event.time.seconds;
dive_add_picture(cur_dive, pic);
} else {
add_event(dc, cur_event.time.seconds,