Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Apr 28, 2023
1 parent 4d5363c commit e02e570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/core/StelLocationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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());
Expand All @@ -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

This comment has been minimized.

Copy link
@gzotti

gzotti Apr 28, 2023

Member

It may be more elegant to have a QRegularExpression which allows two tab-separated names and an optional line comment after hash character.

{
locationDBToIANAtranslations.insert(list.at(0).trimmed().toUtf8(), list.at(1).trimmed().toUtf8());
readOk++;
}
}
}
qDebug() << "Loaded" << readOk << "fixes for time zones";
Expand Down
2 changes: 1 addition & 1 deletion src/core/StelLocationMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e02e570

Please sign in to comment.