diff options
-rw-r--r-- | commands/command_divelist.cpp | 8 | ||||
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/divelist.c | 10 | ||||
-rw-r--r-- | core/divesite.h | 2 | ||||
-rw-r--r-- | core/trip.h | 2 | ||||
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 6 | ||||
-rw-r--r-- | desktop-widgets/divesiteimportdialog.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 12 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 6 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 6 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 8 | ||||
-rw-r--r-- | tests/testmerge.cpp | 12 | ||||
-rw-r--r-- | tests/testrenumber.cpp | 12 |
13 files changed, 47 insertions, 41 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index bf030546b..2f226df3f 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -469,10 +469,10 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str // this only matters if undoit were called before redoit currentDive = nullptr; - struct dive_table dives_to_add = { 0, 0, 0 }; - struct dive_table dives_to_remove = { 0, 0, 0 }; - struct trip_table trips_to_add = { 0, 0, 0 }; - struct dive_site_table sites_to_add = { 0, 0, 0 }; + struct dive_table dives_to_add = empty_dive_table; + struct dive_table dives_to_remove = empty_dive_table; + struct trip_table trips_to_add = empty_trip_table; + struct dive_site_table sites_to_add = empty_dive_site_table; process_imported_dives(dives, trips, sites, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &sites_to_add); // Add trips to the divesToAdd.trips structure diff --git a/core/dive.h b/core/dive.h index b642c3031..e54006dd8 100644 --- a/core/dive.h +++ b/core/dive.h @@ -133,6 +133,8 @@ typedef struct dive_table { struct dive **dives; } dive_table_t; +static const dive_table_t empty_dive_table = { 0, 0, (struct dive **)0 }; + struct picture; struct dive_site; struct dive_site_table; diff --git a/core/divelist.c b/core/divelist.c index 48f5a270c..6995c4c50 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -992,10 +992,10 @@ static bool merge_dive_tables(struct dive_table *dives_from, struct dive_table * void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table, int flags) { int i, idx; - struct dive_table dives_to_add = { 0 }; - struct dive_table dives_to_remove = { 0 }; - struct trip_table trips_to_add = { 0 }; - struct dive_site_table dive_sites_to_add = { 0 }; + struct dive_table dives_to_add = empty_dive_table; + struct dive_table dives_to_remove = empty_dive_table; + struct trip_table trips_to_add = empty_trip_table; + struct dive_site_table dive_sites_to_add = empty_dive_site_table; /* Process imported dives and generate lists of dives * to-be-added and to-be-removed */ @@ -1121,7 +1121,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table * /* If the caller didn't pass an import_trip_table because all * dives are tripless, provide a local table. This may be * necessary if the trips are autogrouped */ - struct trip_table local_trip_table = { 0 }; + struct trip_table local_trip_table = empty_trip_table; if (!import_trip_table) import_trip_table = &local_trip_table; diff --git a/core/divesite.h b/core/divesite.h index d6ec4e51d..30daf3bea 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -31,6 +31,8 @@ typedef struct dive_site_table { struct dive_site **dive_sites; } dive_site_table_t; +static const dive_site_table_t empty_dive_site_table = { 0, 0, (struct dive_site **)0 }; + extern struct dive_site_table dive_site_table; static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table) diff --git a/core/trip.h b/core/trip.h index 51f371589..3a8a2feb7 100644 --- a/core/trip.h +++ b/core/trip.h @@ -24,6 +24,8 @@ typedef struct trip_table { struct dive_trip **trips; } trip_table_t; +static const trip_table_t empty_trip_table = { 0, 0, (struct dive_trip **)0 }; + extern void add_dive_to_trip(struct dive *, dive_trip_t *); extern struct dive_trip *unregister_dive_from_trip(struct dive *dive); extern void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg); diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index 1d6557697..e0d24fd92 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -904,9 +904,9 @@ int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr void DiveLogImportDialog::on_buttonBox_accepted() { - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; QStringList r = resultModel->result(); if (ui->knownImports->currentText() != "Manual import") { for (int i = 0; i < fileNames.size(); ++i) { diff --git a/desktop-widgets/divesiteimportdialog.cpp b/desktop-widgets/divesiteimportdialog.cpp index defb90617..f440d6edb 100644 --- a/desktop-widgets/divesiteimportdialog.cpp +++ b/desktop-widgets/divesiteimportdialog.cpp @@ -65,7 +65,7 @@ void DivesiteImportDialog::on_cancel_clicked() void DivesiteImportDialog::on_ok_clicked() { // delete non-selected dive sites - struct dive_site_table selectedSites = { 0 }; + struct dive_site_table selectedSites = empty_dive_site_table; for (int i = 0; i < importedSites.nr; i++) if (divesiteImportedModel->data(divesiteImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked) { struct dive_site *newSite = alloc_dive_site(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index ddb174984..0b7975054 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1662,9 +1662,9 @@ void MainWindow::importFiles(const QStringList fileNames) return; QByteArray fileNamePtr; - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); @@ -1757,9 +1757,9 @@ void MainWindow::on_actionImportDiveSites_triggered() return; updateLastUsedDir(QFileInfo(fileNames[0]).dir().path()); - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; for (const QString &s: fileNames) { QByteArray fileNamePtr = QFile::encodeName(s); diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 2fecd07a1..658b8196a 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -453,9 +453,9 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) break; } /* parse file and import dives */ - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites); Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de")); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 54eb9490b..9685b7e37 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -380,9 +380,9 @@ void QMLManager::updateAllGlobalLists() void QMLManager::mergeLocalRepo() { char *filename = NOCLOUD_LOCALSTORAGE; - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; parse_file(filename, &table, &trips, &sites); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); } diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index cfadef9b8..b6b5f2402 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -3,8 +3,8 @@ #include "core/divelist.h" DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o), - diveTable({ 0 }), - sitesTable({ 0 }) + diveTable(empty_dive_table), + sitesTable(empty_dive_site_table) { connect(&thread, &QThread::finished, this, &DiveImportedModel::downloadThreadFinished); } @@ -147,8 +147,8 @@ std::pair<struct dive_table, struct dive_site_table> DiveImportedModel::consumeT beginResetModel(); // Move tables to result - struct dive_table dives = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table dives = empty_dive_table; + struct dive_site_table sites = empty_dive_site_table; move_dive_table(&diveTable, &dives); move_dive_site_table(&sitesTable, &sites); diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp index 37ab253cc..f57f85429 100644 --- a/tests/testmerge.cpp +++ b/tests/testmerge.cpp @@ -21,9 +21,9 @@ void TestMerge::testMergeEmpty() /* * check that we correctly merge mixed cylinder dives */ - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0); @@ -47,9 +47,9 @@ void TestMerge::testMergeBackwards() /* * check that we correctly merge mixed cylinder dives */ - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0); diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp index 9d1289906..53da23f65 100644 --- a/tests/testrenumber.cpp +++ b/tests/testrenumber.cpp @@ -13,9 +13,9 @@ void TestRenumber::setup() void TestRenumber::testMerge() { - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 1); @@ -25,9 +25,9 @@ void TestRenumber::testMerge() void TestRenumber::testMergeAndAppend() { - struct dive_table table = { 0 }; - struct trip_table trips = { 0 }; - struct dive_site_table sites = { 0 }; + struct dive_table table = empty_dive_table; + struct trip_table trips = empty_trip_table; + struct dive_site_table sites = empty_dive_site_table; QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 2); |