Use proper sample pointer when deciding to split dives

The dive splitting was completely wrong, because we checked the time of
the previous sample by doing

	sample[i - 1].time.seconds

which is entirely wrong.  The 'sample' variable is the *current* sample,
so the time of the previous sample is simply

	sample[-1].time.seconds

Alternatively, we could have started from the first sample, and done

	dc->sample[i - 1].time.seconds

but mixing the two concepts up just gets you a random sample pointer
that is likely not a valid sample at all, and obviously does not have
the right time at all.

As a result, dive splitting was pretty much random.  Sometimes it worked
purely by mistake, because the rest of the logic was right (ie we _had_
found the right point where we reached the surface in the dive etc, the
"previous sample time" was simply used to decide if the surface interval
was sufficient to split the dive up).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2018-07-01 14:03:39 -07:00 committed by Dirk Hohndel
parent eec9270f32
commit 3209b490dd

View file

@ -3562,7 +3562,7 @@ int split_dive(struct dive *dive)
// the surface start.
if (!surface_start)
continue;
if (!should_split(dc, dc->sample[surface_start].time.seconds, sample[i - 1].time.seconds))
if (!should_split(dc, dc->sample[surface_start].time.seconds, sample[-1].time.seconds))
continue;
return split_dive_at(dive, surface_start, i-1);