diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-20 15:10:31 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-20 15:10:31 -0700 |
commit | 4d9d4825a56d8291b77a55c977b34190d0fb3b31 (patch) | |
tree | cb3ba7c230e3dcea1bc82904ab7e8df0b808d37f /profile.c | |
parent | 04773705e3037900c9389fce6cca1db05cc6db30 (diff) | |
download | subsurface-4d9d4825a56d8291b77a55c977b34190d0fb3b31.tar.gz |
Fix plot entry creation
This was originally triggered by an odd merge of two dives that should
have been the same, but that showed a corner case where the plot entry
creation could create broken results that violated our assumptions about
time stamps being monotonous.
When setting up the plot entries we create surface entries at the
beginning and end. We then fill in the plot entries between them based on
the samples from the dive computer plus our own interpolation (so we have
one entry at least every ten seconds). The loop ends when we are out of
space - which in this instance caused us to exit before updating the
maxtime and therefore the final plot entries having time stamps that were
smaller than the last entry filled in by the inner loop.
This patch makes sure we have enough space in the plot entry structure and
moves the exit from the inner loop until after we have updated the
maxtime.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -551,9 +551,11 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer * * but samples could be more dense than that (so add in dc->samples). We also * need to have one for every event (so count events and add that) and * additionally we want two surface events around the whole thing (thus the - * additional 4). + * additional 4). There is also one extra space for a final entry + * that has time > maxtime (because there can be surface samples + * past "maxtime" in the original sample data) */ - nr = dc->samples + 5 + maxtime / 10 + count_events(dc); + nr = dc->samples + 6 + maxtime / 10 + count_events(dc); plot_data = calloc(nr, sizeof(struct plot_data)); pi->entry = plot_data; if (!plot_data) @@ -604,8 +606,6 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer * ev = ev->next; } - if (time > maxtime) - break; entry->sec = time; entry->depth = depth; @@ -645,6 +645,9 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer * lasttime = time; lastdepth = depth; idx++; + + if (time > maxtime) + break; } /* Add two final surface events */ |