Properly handle dive sites loaded from XML

We used to always create a new dive site structure when loading dive
site data from XML.

That is completely bogus, because it can (and does) create duplicate
dive sites with the same UUID.  Which makes the whole UUID pointless.

So instead, look up the existing dive site associated with the UUID
loaded from the XML, and try to merge the data properly if we already
had dive site information for that UUID.

Reported-by: Alessandro Volpi <volpial@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2017-02-19 14:11:37 -08:00 committed by Dirk Hohndel
parent fc55620d2d
commit 4a550e4d7d
3 changed files with 42 additions and 17 deletions

View file

@ -1569,17 +1569,13 @@ static void dive_site_end(void)
{
if (!cur_dive_site)
return;
if (cur_dive_site->taxonomy.nr == 0) {
free(cur_dive_site->taxonomy.category);
cur_dive_site->taxonomy.category = NULL;
}
if (cur_dive_site->uuid) {
// we intentionally call this with '0' to ensure we get
// a new structure and then copy things into that new
// structure a few lines below (which sets the correct
// uuid)
struct dive_site *ds = alloc_or_get_dive_site(0);
if (cur_dive_site->taxonomy.nr == 0) {
free(cur_dive_site->taxonomy.category);
cur_dive_site->taxonomy.category = NULL;
}
copy_dive_site(cur_dive_site, ds);
struct dive_site *ds = alloc_or_get_dive_site(cur_dive_site->uuid);
merge_dive_site(ds, cur_dive_site);
if (verbose > 3)
printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name);