From 63e1516579977e68a8cd18c7845682d4655b9677 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 16 Jul 2021 21:11:54 +0200 Subject: [PATCH] core: recalculate CNS values on merge When merging two dives, the higher CNS value was taken. This could result in inconsistent CNS values if two dives were merged where one dive's CNS was calculated from a "fake profile", i.e. a dive without dive-computer profile. In that case, the most conservative value (all time spent at the bottom) was assumed. The merged dive then consisted of the dive-computer profile and the conservative CNS estimate. This is fixed by setting the CNS value to "0" after merging, which means "unknown". The correct value will then be recalculated in "fixup_dive" from the actual sample data. Signed-off-by: Berthold Stoeger --- core/dive.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/dive.c b/core/dive.c index e96036611..a4a47ab90 100644 --- a/core/dive.c +++ b/core/dive.c @@ -2614,7 +2614,6 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset, MERGE_MAX(res, a, b, rating); MERGE_TXT(res, a, b, suit, ", "); MERGE_MAX(res, a, b, number); - MERGE_NONZERO(res, a, b, cns); 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); @@ -2631,6 +2630,9 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset, else join_dive_computers(res, &res->dc, &a->dc, &b->dc, cylinders_map_a, cylinders_map_b, 0); + /* The CNS values will be recalculated from the sample in fixup_dive() */ + res->cns = res->maxcns = 0; + /* we take the first dive site, unless it's empty */ *site = a->dive_site && !dive_site_is_empty(a->dive_site) ? a->dive_site : b->dive_site; fixup_dive(res);