[PATCH 2/2] Fix dive computer interleaving so it works again

Linus Torvalds torvalds at linux-foundation.org
Sun Feb 3 21:45:25 PST 2013



From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 4 Feb 2013 16:21:47 +1100
Subject: [PATCH 2/2] Fix dive computer interleaving so it works again

Merging two different dives by interleaving dive computer data got
broken by the multi-dive-computer code in commit b6c9301e5847 ("Move
more dive computer filled data to the divecomputer structure") which
added a lot more entries to the dive computer data structure, and then
copied the resulting structure incorrectly.

Make sure we don't copy the events and samples allocations when we copy
all the other fields of the divecomputer.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

Nobody has apparently done the "merge two adjacent dives into one" 
recently. It was completely buggered.

 dive.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/dive.c b/dive.c
index e054be557217..1280b7cf468c 100644
--- a/dive.c
+++ b/dive.c
@@ -1397,6 +1397,17 @@ static struct divecomputer *find_matching_computer(struct divecomputer *match, s
 	return p;
 }
 
+
+static void copy_dive_computer(struct divecomputer *res, struct divecomputer *a)
+{
+	*res = *a;
+	res->model = a->model ? strdup(a->model) : NULL;
+	res->samples = res->alloc_samples = 0;
+	res->sample = NULL;
+	res->events = NULL;
+	res->next = NULL;
+}
+
 /*
  * Join dive computers with a specific time offset between
  * them.
@@ -1411,9 +1422,7 @@ static void interleave_dive_computers(struct divecomputer *res,
 	do {
 		struct divecomputer *match;
 
-		*res = *a;
-		res->model = a->model ? strdup(a->model) : NULL;
-		res->next = NULL;
+		copy_dive_computer(res, a);
 
 		match = find_matching_computer(a, b);
 		if (match) {
-- 
1.8.1.2.422.g08c0e7f



More information about the subsurface mailing list