[PATCH 3/3] Fix dive computer event handling if there are no samples

Linus Torvalds torvalds at linux-foundation.org
Mon Nov 26 15:23:56 PST 2012

From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 26 Nov 2012 15:12:19 -0800
Subject: [PATCH 3/3] Fix dive computer event handling if there are no samples

This actually triggers for one of our insane test dives (test15): it has
no samples, so we created a fake dive computer entry with the a fake
profile in it, but we didn't copy the events over.

Having a dive with no samples, yet having events from the dive computer,
sounds pretty bogus.  But that test-case did show that when that bogus
situation happens, we had two independent buglets: (a) we didn't insert
the entries in the fake dive computer entry we used and (b) we would
then mix up the events of the fake dive computer entry with the first
dive computer of a dive.

Fix this, just to make test15 happy again.  And eventually, when we
actually plot the information for multiple dive computers, fixing case
(b) would become necessary even for real dives.

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

This fixes a real bug, although one that I don't see happening with any 
actual real-life dive log entry. Our test-case just triggered a rather 
special case situation that got us confused about which event list to use.

 profile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/profile.c b/profile.c
index bbc8c5361e27..a385d6825c66 100644
--- a/profile.c
+++ b/profile.c
@@ -1703,7 +1703,7 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
 	pi->nr = nr;
 	pi_idx = 2; /* the two extra events at the start */
 	/* check for gas changes before the samples start */
-	ev = get_next_event(dive->dc.events, "gaschange");
+	ev = get_next_event(dc->events, "gaschange");
 	while (ev && ev->time.seconds < dc->sample->time.seconds) {
 		entry = pi->entry + pi_idx;
 		entry->sec = ev->time.seconds;
@@ -1716,7 +1716,7 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
 		ev = get_next_event(ev->next, "gaschange");
 	/* find the first deco/ceiling event (if any) */
-	ceil_ev = get_next_event(dive->dc.events, "ceiling");
+	ceil_ev = get_next_event(dc->events, "ceiling");
 	sec = 0;
 	lastindex = 0;
 	lastdepth = -1;
@@ -1958,6 +1958,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
 		fake[2].time.seconds = duration - asc_desc_time;
 		fake[2].depth.mm = maxdepth;
 		fake[3].time.seconds = duration * 1.00;
+		fakedc.events = dc->events;
 		dc = &fakedc;

More information about the subsurface mailing list