From b3dbc8bd6dd920cc8da19f26447b78d94578e4fb Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Tue, 12 Sep 2023 13:06:08 +0200 Subject: [PATCH] Core/World: refactored locale detection to resolve a ill-defined for loop warning --- src/server/game/World/World.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 4b31ea6fbff..f080cc537a7 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -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() ? "" : availableLocalsStr);