Planner: don't return static data in fake_dc()

fake_dc() used to return a statically allocated dc with statically
allocated samples. This is of course a questionable practice in
the light of multi-threading / resource ownership. Once these
problems were recognized, the parameter "alloc" was added. If set
to true, the function would still return a statically allocated
dc, but heap-allocated samples, which could then be copied in
a different dc.

All in all an ownership nightmare and a recipie for disaster.
The returned static dc was only used as a pointer to the samples
anyway. There are four callers of fake_dc() and they all have access
to a dc-structure without samples. Therefore, change the semantics
of fake_dc() to fill out the passed in dc. If the caller does
not care about the samples, it can simply reset the sample number
to zero after work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-05-05 19:26:48 +02:00 committed by Lubomir I. Ivanov
parent 450f0992a0
commit 920ff15f71
7 changed files with 39 additions and 40 deletions

View file

@ -99,7 +99,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
if (dc->samples)
hasMarkedSamples = dc->sample[0].manually_entered;
else
dc = fake_dc(dc, true);
fake_dc(dc);
// if this dive has more than 100 samples (so it is probably a logged dive),
// average samples so we end up with a total of 100 samples.