Core/World: refactored locale detection to resolve a ill-defined for loop warning

This commit is contained in:
Ovahlord
2023-09-12 13:06:08 +02:00
committed by Shauren
parent d11d992df9
commit b3dbc8bd6d

View File

@@ -2247,29 +2247,32 @@ void World::DetectDBCLang()
std::string availableLocalsStr;
uint8 default_locale = TOTAL_LOCALES;
for (uint8 i = default_locale-1; i < TOTAL_LOCALES; --i) // -1 will be 255 due to uint8
for (uint8 i = LOCALE_enUS; i < TOTAL_LOCALES; ++i)
{
if (race->Name[i][0] != '\0') // check by race names
{
default_locale = i;
// Mark the first found locale as default locale
if (default_locale == TOTAL_LOCALES)
default_locale = i;
m_availableDbcLocaleMask |= (1 << i);
availableLocalsStr += localeNames[i];
availableLocalsStr += " ";
}
}
if (m_availableDbcLocaleMask == 0)
{
TC_LOG_ERROR("server.loading", "Unable to determine your DBC Locale! (corrupt DBC?)");
exit(1);
}
if (default_locale != m_lang_confid && m_lang_confid < TOTAL_LOCALES &&
(m_availableDbcLocaleMask & (1 << m_lang_confid)))
{
default_locale = m_lang_confid;
}
if (default_locale >= TOTAL_LOCALES)
{
TC_LOG_ERROR("server.loading", "Unable to determine your DBC Locale! (corrupt DBC?)");
exit(1);
}
m_defaultDbcLocale = LocaleConstant(default_locale);
TC_LOG_INFO("server.loading", "Using {} DBC Locale as default. All available DBC locales: {}", localeNames[m_defaultDbcLocale], availableLocalsStr.empty() ? "<none>" : availableLocalsStr);