From 920ff15f7160cfa6ed8d8d81e0c156dd1d7b27c6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 5 May 2018 19:26:48 +0200 Subject: 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 --- mobile-widgets/qmlmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index bd8ea29a3..a7345363c 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1089,9 +1089,9 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q // so we have depth > 0, a manually added dive and no samples // let's create an actual profile so the desktop version can work it // first clear out the mean depth (or the fake_dc() function tries - // to be too clever + // to be too clever) d->meandepth.mm = d->dc.meandepth.mm = 0; - d->dc = *fake_dc(&d->dc, true); + fake_dc(&d->dc); } fixup_dive(d); DiveListModel::instance()->updateDive(modelIdx, d); -- cgit v1.2.3-70-g09d2