From 77e5dbac7309d6bc09d6ef2631857d41486f3ac8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 29 Jun 2019 10:27:48 +0200 Subject: [PATCH] Undo: Make PasteState cylinders list dynamically allocated Instead of using a sub-array, use a std::vector<>. This is a necessary step in removing the MAX_CYLINDERS restriction. Signed-off-by: Berthold Stoeger --- desktop-widgets/command_edit.cpp | 9 ++++++--- desktop-widgets/command_edit.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index 5f6f0be3f..95665722d 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -687,7 +687,8 @@ static void swapCandQString(QString &q, char *&c) } PasteState::PasteState(dive *dIn, const dive *data, dive_components what) : d(dIn), - tags(nullptr) + tags(nullptr), + cylinders(MAX_CYLINDERS) { memset(&cylinders[0], 0, sizeof(cylinders)); memset(&weightsystems, 0, sizeof(weightsystems)); @@ -742,8 +743,10 @@ void PasteState::swap(dive_components what) std::swap(divesite, d->dive_site); if (what.tags) std::swap(tags, d->tag_list); - if (what.cylinders) - std::swap(cylinders, d->cylinder); + if (what.cylinders) { + for (int i = 0; i < MAX_CYLINDERS; ++i) + std::swap(cylinders[i], d->cylinder[i]); + } if (what.weights) std::swap(weightsystems, d->weightsystems); } diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h index ebce0bf1b..489c51046 100644 --- a/desktop-widgets/command_edit.h +++ b/desktop-widgets/command_edit.h @@ -246,7 +246,7 @@ struct PasteState { int rating; int visibility; tag_entry *tags; - cylinder_t cylinders[MAX_CYLINDERS]; + std::vector cylinders; struct weightsystem_table weightsystems; PasteState(dive *d, const dive *data, dive_components what); // Read data from dive data for dive d