Codechange: prevent out-of-bound read (even if the result is never used) (#11853)

(cherry picked from commit fe035c306e)
This commit is contained in:
Patric Stout
2024-01-21 15:25:00 +01:00
committed by Jonathan G Rennison
parent be147651d4
commit 90859fbe25
2 changed files with 3 additions and 1 deletions

View File

@@ -18,6 +18,8 @@
/* static */ AIConfig *AIConfig::GetConfig(CompanyID company, ScriptSettingSource source)
{
assert(company < MAX_COMPANIES);
AIConfig **config;
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
config = &_settings_newgame.ai_config[company];

View File

@@ -288,7 +288,7 @@ struct AIConfigWindow : public Window {
if (!gui_scope) return;
AIConfig *config = AIConfig::GetConfig(this->selected_slot);
AIConfig *config = this->selected_slot == INVALID_COMPANY ? nullptr : AIConfig::GetConfig(this->selected_slot);
this->SetWidgetDisabledState(WID_AIC_DECREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == 0);
this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);