core: avoid crash when merging dive with no cylinders

Arguably every dive should at least have one cylinder, but an imported
dive from divelogs.de might end up without one. Sadly, that breaks
assumptions that we make in the cylinder remapping.

To work around it, force at least on cylinder to be assumed in the merge
code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-04-23 15:01:42 -07:00
parent 5a5188bc47
commit 8d9730f74f
2 changed files with 5 additions and 2 deletions

View file

@ -1,3 +1,4 @@
- core: prevent crash when merging dives without cylinders (as we might get when importing from divelogs.de)
- core: work around bug in TecDiving dive computer reporting spurious 0 deg C water temperature in first sample
- core: correctly parse DC_FIELD_SALINITY response; fixes incorrect water type with some dive computers, including the Mares Smart
- Desktop: Allow more than one media file to be imported from web

View file

@ -2623,8 +2623,10 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset,
MERGE_NONZERO(res, a, b, visibility);
copy_pictures(a->pictures.nr ? &a->pictures : &b->pictures, &res->pictures);
taglist_merge(&res->tag_list, a->tag_list, b->tag_list);
cylinders_map_a = malloc(a->cylinders.nr * sizeof(*cylinders_map_a));
cylinders_map_b = malloc(b->cylinders.nr * sizeof(*cylinders_map_b));
/* if we get dives without any gas / cylinder information in an import, make sure
* that there is at leatst one entry in the cylinder map for that dive */
cylinders_map_a = malloc(MAX(1, a->cylinders.nr) * sizeof(*cylinders_map_a));
cylinders_map_b = malloc(MAX(1, b->cylinders.nr) * sizeof(*cylinders_map_b));
merge_cylinders(res, a, b, cylinders_map_a, cylinders_map_b);
merge_equipment(res, a, b);
merge_temperatures(res, a, b);