Skip to content

Commit e42d4e4

Browse files
authored
[GEN][ZH] Suppress compiler warning about buffer overrun while writing to 'newIndices' in PopulateLobbyPlayerListbox() (#1132)
1 parent da33465 commit e42d4e4

File tree

2 files changed

+18
-10
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+18
-10
lines changed

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,18 @@ void PopulateLobbyPlayerListbox(void)
568568
// restore selection
569569
if (indicesToSelect.size())
570570
{
571-
std::set<Int>::const_iterator indexIt;
572-
Int *newIndices = NEW Int[indicesToSelect.size()];
573-
for (i=0, indexIt = indicesToSelect.begin(); indexIt != indicesToSelect.end(); ++i, ++indexIt)
571+
std::set<Int>::const_iterator indexIt = indicesToSelect.begin();
572+
const size_t count = indicesToSelect.size();
573+
size_t index = 0;
574+
Int *newIndices = NEW Int[count];
575+
while (index < count)
574576
{
575-
newIndices[i] = *indexIt;
577+
newIndices[index] = *indexIt;
576578
DEBUG_LOG(("Queueing up index %d to re-select\n", *indexIt));
579+
++index;
580+
++indexIt;
577581
}
578-
GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, indicesToSelect.size());
582+
GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, count);
579583
delete[] newIndices;
580584
}
581585

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,18 @@ void PopulateLobbyPlayerListbox(void)
585585
// restore selection
586586
if (indicesToSelect.size())
587587
{
588-
std::set<Int>::const_iterator indexIt;
589-
Int *newIndices = NEW Int[indicesToSelect.size()];
590-
for (i=0, indexIt = indicesToSelect.begin(); indexIt != indicesToSelect.end(); ++i, ++indexIt)
588+
std::set<Int>::const_iterator indexIt = indicesToSelect.begin();
589+
const size_t count = indicesToSelect.size();
590+
size_t index = 0;
591+
Int *newIndices = NEW Int[count];
592+
while (index < count)
591593
{
592-
newIndices[i] = *indexIt;
594+
newIndices[index] = *indexIt;
593595
DEBUG_LOG(("Queueing up index %d to re-select\n", *indexIt));
596+
++index;
597+
++indexIt;
594598
}
595-
GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, indicesToSelect.size());
599+
GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, count);
596600
delete[] newIndices;
597601
}
598602

0 commit comments

Comments
 (0)