Skip to content

Commit e02e570

Browse files
committed
Fix crash
1 parent 4d5363c commit e02e570

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/core/StelLocationMgr.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ StelLocationMgr::StelLocationMgr()
411411
QSettings* conf = StelApp::getInstance().getSettings();
412412

413413
// N.B. Further missing TZ names will be printed out in the log.txt. Resolve these by adding into data/timezone.tab file.
414-
loadTimeZones();
414+
loadTimeZoneFixes();
415415

416416
loadCountries();
417417
loadRegions();
@@ -1182,17 +1182,17 @@ void StelLocationMgr::loadCountries()
11821182
countryNameToCodeMap.insert("Taiwan (Provice of China)", "tw");
11831183
}
11841184

1185-
void StelLocationMgr::loadTimeZones()
1185+
void StelLocationMgr::loadTimeZoneFixes()
11861186
{
1187-
QString tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::File);
1187+
QString tzFilePath = StelFileMgr::findFile(tzfFileName);
11881188
if (tzFilePath.isEmpty())
11891189
{
11901190
tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::New);
1191-
// Create a default TZF (time zone fixes) file
1191+
// Create a default TZF (timezone fixes) file
11921192
QFile tzSrc(":/data/timezone.tab");
11931193
if (!tzSrc.copy(tzFilePath))
11941194
{
1195-
qWarning() << "Cannot copy time zones file to " + QDir::toNativeSeparators(tzFilePath);
1195+
qWarning() << "Cannot copy timezone fixes to " + QDir::toNativeSeparators(tzFilePath);
11961196
return;
11971197
}
11981198
}
@@ -1202,8 +1202,8 @@ void StelLocationMgr::loadTimeZones()
12021202
{
12031203
locationDBToIANAtranslations.clear();
12041204
QString line;
1205-
int readOk=0;
1206-
locationDBToIANAtranslations.insert("", "UTC");
1205+
locationDBToIANAtranslations.insert("", "UTC"); // a first fix
1206+
int readOk = 1;
12071207
while(!tzFile.atEnd())
12081208
{
12091209
line = QString::fromUtf8(tzFile.readLine());
@@ -1219,8 +1219,11 @@ void StelLocationMgr::loadTimeZones()
12191219
#endif
12201220

12211221
// The first entry is the DB name, the second is as we display it in the program.
1222-
locationDBToIANAtranslations.insert(list.at(0).trimmed().toLocal8Bit(), list.at(1).trimmed().toLocal8Bit());
1223-
readOk++;
1222+
if (list.count()==2) // to avoid crashes
1223+
{
1224+
locationDBToIANAtranslations.insert(list.at(0).trimmed().toUtf8(), list.at(1).trimmed().toUtf8());
1225+
readOk++;
1226+
}
12241227
}
12251228
}
12261229
qDebug() << "Loaded" << readOk << "fixes for time zones";

src/core/StelLocationMgr.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private slots:
160160
private:
161161
void loadRegions();
162162
void loadCountries();
163-
void loadTimeZones();
163+
void loadTimeZoneFixes();
164164
void generateBinaryLocationFile(const QString& txtFile, bool isUserLocation, const QString& binFile) const;
165165

166166
//! Load cities from a file

0 commit comments

Comments
 (0)