bugfix(money): Fix undefined behavior for starting cash combo box#2582
bugfix(money): Fix undefined behavior for starting cash combo box#2582Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp | Fixes UB caused by dereferencing the end iterator after the loop; also tightens it's scope to the loop itself. |
| Generals/Code/GameEngine/Include/GameNetwork/GUIUtil.h | Removes orphaned declaration of PopulateStartingCashComboBox, which was never defined in the vanilla Generals code tree. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PopulateStartingCashComboBox called] --> B[Reset combo box]
B --> C[Iterate over startingCashMap]
C --> D{amountEqual current cash?}
D -- Yes --> E[Set currentSelectionIndex = newIndex]
D -- No --> C
C -- Loop ends --> F{currentSelectionIndex == -1?}
E --> F
F -- No --> G[GadgetComboBoxSetSelectedPos]
F -- Yes --> H[DEBUG_CRASH]
H --> I[Add custom entry to combo box]
I --> J["Set item data: myGame->getStartingCash().countMoney() ✅ (was: it->countMoney() on end iterator ❌)"]
J --> G
Reviews (2): Last reviewed commit: "Removed unused function declaration in G..." | Re-trigger Greptile
|
Updated PR. It looks like |
| void PopulateColorComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool isObserver = FALSE); | ||
| void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool allowObservers ); | ||
| void PopulateTeamComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool isObserver = FALSE); | ||
| void PopulateStartingCashComboBox(GameWindow *comboBox, GameInfo *myGame); |
There was a problem hiding this comment.
This may be here because we already merged code from Zero Hour to Generals. You can keep it.
Players that modify their
GlobalData::m_defaultStartingCashvalue may see strange behavior when it comes to their starting cash (skirmish and multiplayer). That's because the game dereferences an end iterator if it cannot find one of the four default starting cash values. This crashes the game in debug builds and it may produce 'random' starting cash values in release builds. (Even though the starting cash is unsigned, the visual amount may show up as negative in the control bar).TODO: