Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server: Fix --serverinfo country code misinterpretation on Qt6 #2829

Merged
merged 2 commits into from
Sep 12, 2022
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 ) )
pljones marked this conversation as resolved.
Show resolved Hide 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 )
pljones marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}
return qt6CountryToWireFormat[iCountryCode] != -1;
#else
// All Qt5 codes are supported.
Q_UNUSED ( iCountryCode );
return true;
return iCountryCode <= QLocale::LastCountry;
pljones marked this conversation as resolved.
Show resolved Hide 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