Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/serverlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
// [this server country as QLocale ID]
bool ok;
const int iCountry = slServInfoSeparateParams[2].toInt ( &ok );
if ( ok && iCountry >= 0 && iCountry <= QLocale::LastCountry )
if ( ok && iCountry >= 0 && CLocale::IsCountryCodeSupported ( iCountry ) )
Comment thread
pljones marked this conversation as resolved.
{
ThisServerListEntry.eCountry = static_cast<QLocale::Country> ( iCountry );
// Convert from externally-supplied format ("wire format", Qt5 codes) to
// native format. On Qt5 builds, this is a noop, on Qt6 builds, a conversion
// takes place.
// We try to do such conversions at the outer-most interface which is capable of doing it.
// Although the value comes from src/main -> src/server, this very place is
// the first where we have access to the parsed country code:
ThisServerListEntry.eCountry = CLocale::WireFormatCountryCodeToQtCountry ( iCountry );
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,11 +1423,16 @@ bool CLocale::IsCountryCodeSupported ( unsigned short iCountryCode )
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
// On newer Qt versions there might be codes which do not have a Qt5 equivalent.
// We have no way to support those sanely right now.
// Before we can check that via an array lookup, we have to ensure that
// we are within the boundaries of that array:
if ( iCountryCode >= qt6CountryToWireFormatLen )
Comment thread
pljones marked this conversation as resolved.
{
return false;
}
return qt6CountryToWireFormat[iCountryCode] != -1;
#else
// All Qt5 codes are supported.
Q_UNUSED ( iCountryCode );
return true;
return iCountryCode <= QLocale::LastCountry;
Comment thread
pljones marked this conversation as resolved.
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ class CLocale
195, 196, 114, 254, 197, 198, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 62, 212, 213, 214, 215, 253, 216, 217, 218, 219, 220,
221, 222, 223, 224, 226, 225, 234, 227, 228, 229, 230, 231, 232, 235, 236, 260, 237, 239, 240,
};
constexpr int const static qt6CountryToWireFormatLen = sizeof ( qt6CountryToWireFormat ) / sizeof ( qt6CountryToWireFormat[0] );
#endif
};

Expand Down