Ensure each dive has its own copy of the location text (UEMIS importer)

Since multiple dives can reference the same divesite we need to do the
strdup when the value gets assigned, not when it gets passed into the
helper function.

This also validates the location string as on my divecomputer there is an
invalid divespot 0 that has a corrupted UTF8 string as location name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-01-23 11:55:29 -08:00
parent b1db60ba47
commit 3e5a508b15
2 changed files with 4 additions and 2 deletions

View file

@ -575,7 +575,7 @@ static void parse_divespot(char *buf)
latitude = g_ascii_strtod(val, NULL);
}
} while (tag && *tag);
uemis_set_divelocation(divespot, strdup(locationstring), latitude, longitude);
uemis_set_divelocation(divespot, locationstring, latitude, longitude);
}
static void track_divespot(char *val, int diveid, char **location, degrees_t *latitude, degrees_t *longitude)

View file

@ -166,9 +166,11 @@ void uemis_mark_divelocation(int diveid, int divespot, char **location, degrees_
void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude)
{
struct uemis_helper *hp = uemis_helper;
if (!g_utf8_validate(text, -1, NULL))
return;
while (hp) {
if (hp->divespot == divespot && hp->location) {
*hp->location = text;
*hp->location = strdup(text);
hp->longitude->udeg = round(longitude * 1000000);
hp->latitude->udeg = round(latitude * 1000000);
}