mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
e3a8ed5183
commit
9b47dc1f59
1 changed files with 11 additions and 2 deletions
13
parse-xml.c
13
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue