From e02e570a59ddd3c1ec83407b78c88d710980724f Mon Sep 17 00:00:00 2001 From: "Alexander V. Wolf" Date: Fri, 28 Apr 2023 13:38:04 +0700 Subject: [PATCH] Fix crash --- src/core/StelLocationMgr.cpp | 21 ++++++++++++--------- src/core/StelLocationMgr.hpp | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/core/StelLocationMgr.cpp b/src/core/StelLocationMgr.cpp index 6921ba1a6b79c..36395f30d81b1 100644 --- a/src/core/StelLocationMgr.cpp +++ b/src/core/StelLocationMgr.cpp @@ -411,7 +411,7 @@ StelLocationMgr::StelLocationMgr() QSettings* conf = StelApp::getInstance().getSettings(); // N.B. Further missing TZ names will be printed out in the log.txt. Resolve these by adding into data/timezone.tab file. - loadTimeZones(); + loadTimeZoneFixes(); loadCountries(); loadRegions(); @@ -1182,17 +1182,17 @@ void StelLocationMgr::loadCountries() countryNameToCodeMap.insert("Taiwan (Provice of China)", "tw"); } -void StelLocationMgr::loadTimeZones() +void StelLocationMgr::loadTimeZoneFixes() { - QString tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::File); + QString tzFilePath = StelFileMgr::findFile(tzfFileName); if (tzFilePath.isEmpty()) { tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::New); - // Create a default TZF (time zone fixes) file + // Create a default TZF (timezone fixes) file QFile tzSrc(":/data/timezone.tab"); if (!tzSrc.copy(tzFilePath)) { - qWarning() << "Cannot copy time zones file to " + QDir::toNativeSeparators(tzFilePath); + qWarning() << "Cannot copy timezone fixes to " + QDir::toNativeSeparators(tzFilePath); return; } } @@ -1202,8 +1202,8 @@ void StelLocationMgr::loadTimeZones() { locationDBToIANAtranslations.clear(); QString line; - int readOk=0; - locationDBToIANAtranslations.insert("", "UTC"); + locationDBToIANAtranslations.insert("", "UTC"); // a first fix + int readOk = 1; while(!tzFile.atEnd()) { line = QString::fromUtf8(tzFile.readLine()); @@ -1219,8 +1219,11 @@ void StelLocationMgr::loadTimeZones() #endif // The first entry is the DB name, the second is as we display it in the program. - locationDBToIANAtranslations.insert(list.at(0).trimmed().toLocal8Bit(), list.at(1).trimmed().toLocal8Bit()); - readOk++; + if (list.count()==2) // to avoid crashes + { + locationDBToIANAtranslations.insert(list.at(0).trimmed().toUtf8(), list.at(1).trimmed().toUtf8()); + readOk++; + } } } qDebug() << "Loaded" << readOk << "fixes for time zones"; diff --git a/src/core/StelLocationMgr.hpp b/src/core/StelLocationMgr.hpp index b63f1f03d65f2..62623c92c659e 100644 --- a/src/core/StelLocationMgr.hpp +++ b/src/core/StelLocationMgr.hpp @@ -160,7 +160,7 @@ private slots: private: void loadRegions(); void loadCountries(); - void loadTimeZones(); + void loadTimeZoneFixes(); void generateBinaryLocationFile(const QString& txtFile, bool isUserLocation, const QString& binFile) const; //! Load cities from a file