summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-16 12:33:37 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-16 15:48:32 -1000
commit7b457d1b5c44db5db1a2bace178fd9c3e447a65c (patch)
tree78cbe4748a77665af33972da941070fcde470190
parent459696c90c94834b7498a1b20cd6ccb85bfaa9e0 (diff)
downloadsubsurface-7b457d1b5c44db5db1a2bace178fd9c3e447a65c.tar.gz
Properly remove redundant dive computer information
We had logic to remove duplicate dive computer information after merging dives, but it didn't actually work. Why? Because we had used the 'res' dive computer pointer to traverse the list of dive computers, so it no longer actually pointed to the first dive computer in the result list any more, and so the "remove redundant" code only removed redundant dive computers from a limited and incomplete list. Oops. Also, before checking the whole event and sample list, check if it's the exact same dive computer using our new "match_one_dc()" helper function, and don't even bother checking for sample details if it is. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/dive.c b/dive.c
index 2a5b17580..a59bb5fc0 100644
--- a/dive.c
+++ b/dive.c
@@ -1285,6 +1285,10 @@ static int same_dc(struct divecomputer *a, struct divecomputer *b)
int i;
struct event *eva, *evb;
+ i = match_one_dc(a, b);
+ if (i)
+ return i > 0;
+
if (a->when && b->when && a->when != b->when)
return 0;
if (a->samples != b->samples)
@@ -1406,6 +1410,8 @@ static void interleave_dive_computers(struct divecomputer *res,
*/
static void join_dive_computers(struct divecomputer *res, struct divecomputer *a, struct divecomputer *b)
{
+ struct divecomputer *tmp;
+
if (a->model && !b->model) {
*res = *a;
clear_dc(a);
@@ -1419,11 +1425,12 @@ static void join_dive_computers(struct divecomputer *res, struct divecomputer *a
*res = *a;
clear_dc(a);
- while (res->next)
- res = res->next;
+ tmp = res;
+ while (tmp->next)
+ tmp = tmp->next;
- res->next = calloc(1, sizeof(*res));
- *res->next = *b;
+ tmp->next = calloc(1, sizeof(*tmp));
+ *tmp->next = *b;
clear_dc(b);
remove_redundant_dc(res);