aboutsummaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Henrik Brautaset Aronsen <subsurface@henrik.synth.no>2013-01-29 22:30:02 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-30 12:06:33 +1100
commit9b47dc1f5920be228d2b4e6b91f361a52d40eb87 (patch)
tree7f68c38eec757ae1905d343e21f405d6a902cfca /parse-xml.c
parente3a8ed5183ed5a24e391395c9faeae03dc9e4a6a (diff)
downloadsubsurface-9b47dc1f5920be228d2b4e6b91f361a52d40eb87.tar.gz
Make sure imported rating and visibility are within limits.
The "visibility" value in MacDive XML files could be a random string, while it's a value of 0-5 in Subsurface. Importing an illegal value (such as "11m") resulted in a segfault from libpangocairo and an "Invalid UTF-8 string passed to pango_layout_set_text()". [Dirk Hohndel: fixed int * vs. int issue] Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 30b616324..184a0e89d 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -458,6 +458,15 @@ static void get_index(char *buffer, void *_i)
*i = atoi(buffer);
}
+static void get_rating(char *buffer, void *_i)
+{
+ int *i = _i;
+ int j = atoi(buffer);
+ if (j >= 0 && j <= 5) {
+ *i = j;
+ }
+}
+
static void double_to_permil(char *buffer, void *_i)
{
int *i = _i;
@@ -1024,9 +1033,9 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
return;
if (MATCH(".buddy", utf8_string, &dive->buddy))
return;
- if (MATCH(".rating", get_index, &dive->rating))
+ if (MATCH("dive.rating", get_rating, &dive->rating))
return;
- if (MATCH(".visibility", get_index, &dive->visibility))
+ if (MATCH("dive.visibility", get_rating, &dive->visibility))
return;
if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cur_cylinder_index].type.size))
return;