diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ab3a100..3e4558bd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/dive.c b/core/dive.c index 03eb82e70..1d20e1421 100644 --- a/core/dive.c +++ b/core/dive.c @@ -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);