summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-03 23:08:32 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-05 10:14:25 -0800
commitdc67876c7955b21f969545eee6f3ae3bdb550787 (patch)
treeea9fd130fa10807410a7376799f03f46a2fbc64b
parent92b833a7d85f7d361f2b198782bb093c300ed59a (diff)
downloadsubsurface-dc67876c7955b21f969545eee6f3ae3bdb550787.tar.gz
Cleanup: introduce empty_weightsystem constant
To make things more future-proof, introduce an empty_weightsystem constant. Replace explicit aggragate initialization of empty weightsystems by this constant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--commands/command_edit.cpp5
-rw-r--r--core/equipment.h2
-rw-r--r--core/parse.c3
-rw-r--r--qt-models/weightmodel.cpp2
4 files changed, 6 insertions, 6 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index bfa02a55d..d0d9fc087 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -978,9 +978,8 @@ void AddWeight::undo()
void AddWeight::redo()
{
- weightsystem_t ws { {0}, "" };
for (dive *d: dives) {
- add_cloned_weightsystem(&d->weightsystems, ws);
+ add_cloned_weightsystem(&d->weightsystems, empty_weightsystem);
emit diveListNotifier.weightAdded(d, d->weightsystems.nr - 1);
}
}
@@ -996,7 +995,7 @@ static int find_weightsystem_index(const struct dive *d, weightsystem_t ws)
RemoveWeight::RemoveWeight(int index, bool currentDiveOnly) :
EditDivesBase(currentDiveOnly),
- ws{ {0}, nullptr }
+ ws(empty_weightsystem)
{
// Get the old weightsystem, bail if index is invalid
if (!current || index < 0 || index >= current->weightsystems.nr) {
diff --git a/core/equipment.h b/core/equipment.h
index 687e794a5..2711d7703 100644
--- a/core/equipment.h
+++ b/core/equipment.h
@@ -50,6 +50,8 @@ typedef struct
const char *description; /* "integrated", "belt", "ankle" */
} weightsystem_t;
+static const weightsystem_t empty_weightsystem = { { 0 }, 0 };
+
/* Table of weightsystems. Attention: this stores weightsystems,
* *not* pointers * to weightsystems. This has two crucial
* consequences:
diff --git a/core/parse.c b/core/parse.c
index 30d6a8ad5..56e5928fc 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -298,8 +298,7 @@ void cylinder_end(struct parser_state *state)
void ws_start(struct parser_state *state)
{
- weightsystem_t w = { {0}, "" };
- add_cloned_weightsystem(&state->cur_dive->weightsystems, w);
+ add_cloned_weightsystem(&state->cur_dive->weightsystems, empty_weightsystem);
}
void ws_end(struct parser_state *state)
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index c8903d069..087d877ab 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -23,7 +23,7 @@ weightsystem_t WeightModel::weightSystemAt(const QModelIndex &index) const
int row = index.row();
if (row < 0 || row >= d->weightsystems.nr) {
qWarning("WeightModel: Accessing invalid weightsystem %d (of %d)", row, d->weightsystems.nr);
- return { { 0 }, nullptr };
+ return empty_weightsystem;
}
return d->weightsystems.weightsystems[index.row()];
}