summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2018-07-01 14:03:39 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-02 08:36:53 -0700
commit3209b490ddda7b029392a030e34097b921bfd025 (patch)
treea34b2e08aed2f656790ca0c085c46bd6b42f4ba3
parenteec9270f32d9e9a7b11b825464b713d3160bd633 (diff)
downloadsubsurface-3209b490ddda7b029392a030e34097b921bfd025.tar.gz
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>
-rw-r--r--core/dive.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/dive.c b/core/dive.c
index 3b3ad762d..1ecfb923f 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -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);