1
0
Fork 0

Fix c2d4098afa: Crash when accessing unconfigurable badge feature. (#14403)

Some features support badges but do not have a way to configure them. Accessing these features could crash the game.
pull/14404/head
Peter Nelson 2025-06-30 21:45:08 +01:00 committed by GitHub
parent 36d7e09369
commit 4fe6adb2dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 6 deletions

View File

@ -118,14 +118,16 @@ void ResetBadgeClassConfiguration(GrfSpecFeature feature)
*/ */
std::pair<const BadgeClassConfigItem &, int> GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label) std::pair<const BadgeClassConfigItem &, int> GetBadgeClassConfigItem(GrfSpecFeature feature, std::string_view label)
{ {
if (BadgeClassConfig::CONFIGURABLE_FEATURES.Test(feature)) {
auto config = GetBadgeClassConfiguration(feature); auto config = GetBadgeClassConfiguration(feature);
auto found = std::ranges::find(config, label, &BadgeClassConfigItem::label); auto found = std::ranges::find(config, label, &BadgeClassConfigItem::label);
if (found == std::end(config)) { if (found != std::end(config)) {
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
}
/* Sort order is simply the position in the configuration list. */ /* Sort order is simply the position in the configuration list. */
return {*found, static_cast<int>(std::distance(std::begin(config), found))}; return {*found, static_cast<int>(std::distance(std::begin(config), found))};
}
}
return {BadgeClassConfig::EMPTY_CONFIG_ITEM, 0};
} }
/** /**