Skip to content

Commit c9a4e3a

Browse files
authored
[GEN][ZH] Prevent dereferencing NULL pointer 'player' in setObserverWindows() (#1137)
1 parent 460c73d commit c9a4e3a

File tree

2 files changed

+12
-24
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+12
-24
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ static void updateChallengeMedals(Int& medals)
11781178
//-------------------------------------------------------------------------------------------------
11791179
void populatePlayerInfo( Player *player, Int pos)
11801180
{
1181-
if(!player || pos > MAX_SLOTS)
1181+
if(!player || pos < 0 || pos >= MAX_SLOTS)
11821182
return;
11831183
Color color = player->getPlayerColor();
11841184
ScoreKeeper *scoreKpr = player->getScoreKeeper();
@@ -2071,7 +2071,7 @@ winName.format("ScoreScreen.wnd:StaticTextScore%d", i);
20712071
//-------------------------------------------------------------------------------------------------
20722072
void setObserverWindows( Player *player, Int i )
20732073
{
2074-
if(i < 0 || i >= MAX_SLOTS)
2074+
if(!player || i < 0 || i >= MAX_SLOTS)
20752075
return;
20762076
AsciiString winName;
20772077
GameWindow *win;
@@ -2082,16 +2082,10 @@ void setObserverWindows( Player *player, Int i )
20822082
winName.format("ScoreScreen.wnd:StaticTextPlayer%d", i);
20832083
win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey( winName ) );
20842084
DEBUG_ASSERTCRASH(win,("Could not find window %s on the score screen", winName.str()));
2085-
if (player)
2086-
{
2087-
GadgetStaticTextSetText(win, player->getPlayerDisplayName());
2088-
win->winHide(FALSE);
2089-
win->winSetEnabledTextColors(color, win->winGetEnabledTextBorderColor());
2090-
}
2091-
else
2092-
{
2093-
win->winHide(TRUE);
2094-
}
2085+
2086+
GadgetStaticTextSetText(win, player->getPlayerDisplayName());
2087+
win->winHide(FALSE);
2088+
win->winSetEnabledTextColors(color, win->winGetEnabledTextBorderColor());
20952089

20962090
// set the player name
20972091
winName.format("ScoreScreen.wnd:StaticTextObserver%d", i);

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ static inline int CheckForApocalypse( ScoreKeeper *s, const char* szWeapon )
14121412
//-------------------------------------------------------------------------------------------------
14131413
void populatePlayerInfo( Player *player, Int pos)
14141414
{
1415-
if(!player || pos > MAX_SLOTS)
1415+
if(!player || pos < 0 || pos >= MAX_SLOTS)
14161416
return;
14171417
Color color = player->getPlayerColor();
14181418
ScoreKeeper *scoreKpr = player->getScoreKeeper();
@@ -2339,7 +2339,7 @@ winName.format("ScoreScreen.wnd:StaticTextScore%d", i);
23392339
//-------------------------------------------------------------------------------------------------
23402340
void setObserverWindows( Player *player, Int i )
23412341
{
2342-
if(i < 0 || i >= MAX_SLOTS)
2342+
if(!player || i < 0 || i >= MAX_SLOTS)
23432343
return;
23442344
AsciiString winName;
23452345
GameWindow *win;
@@ -2350,16 +2350,10 @@ void setObserverWindows( Player *player, Int i )
23502350
winName.format("ScoreScreen.wnd:StaticTextPlayer%d", i);
23512351
win = TheWindowManager->winGetWindowFromId( parent, TheNameKeyGenerator->nameToKey( winName ) );
23522352
DEBUG_ASSERTCRASH(win,("Could not find window %s on the score screen", winName.str()));
2353-
if (player)
2354-
{
2355-
GadgetStaticTextSetText(win, player->getPlayerDisplayName());
2356-
win->winHide(FALSE);
2357-
win->winSetEnabledTextColors(color, win->winGetEnabledTextBorderColor());
2358-
}
2359-
else
2360-
{
2361-
win->winHide(TRUE);
2362-
}
2353+
2354+
GadgetStaticTextSetText(win, player->getPlayerDisplayName());
2355+
win->winHide(FALSE);
2356+
win->winSetEnabledTextColors(color, win->winGetEnabledTextBorderColor());
23632357

23642358
// set the player name
23652359
winName.format("ScoreScreen.wnd:StaticTextObserver%d", i);

0 commit comments

Comments
 (0)