Skip to content

Commit 20c5ce1

Browse files
GadgetListBox: Add safety check and clear child window pointers
1 parent 4b359f0 commit 20c5ce1

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ static void adjustDisplay( GameWindow *window, Int adjustment,
258258
GameWindow *child;
259259

260260
sData = (SliderData *)list->slider->winGetUserData();
261+
262+
// Safety check: ensure slider data is valid before accessing it
263+
if( sData == NULL )
264+
return;
265+
261266
list->slider->winGetSize( &sliderSize.x, &sliderSize.y );
262267
// Take into account that there is a line-drawn outline surrounding listbox
263268
sData->maxVal = list->totalHeight - ( list->displayHeight - TOTAL_OUTLINE_HEIGHT ) + 1;
@@ -1973,6 +1978,11 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
19731978
if( list->multiSelect )
19741979
delete[]( list->selections );
19751980

1981+
// Clear child window pointers to prevent dangling pointer access
1982+
list->slider = NULL;
1983+
list->upButton = NULL;
1984+
list->downButton = NULL;
1985+
19761986
delete (ListboxData *)window->winGetUserData();
19771987
window->winSetUserData( NULL );
19781988
list = NULL;

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ static void adjustDisplay( GameWindow *window, Int adjustment,
258258
GameWindow *child;
259259

260260
sData = (SliderData *)list->slider->winGetUserData();
261+
262+
// Safety check: ensure slider data is valid before accessing it
263+
if( sData == NULL )
264+
return;
265+
261266
list->slider->winGetSize( &sliderSize.x, &sliderSize.y );
262267
// Take into account that there is a line-drawn outline surrounding listbox
263268
sData->maxVal = list->totalHeight - ( list->displayHeight - TOTAL_OUTLINE_HEIGHT ) + 1;
@@ -1973,6 +1978,11 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg,
19731978
if( list->multiSelect )
19741979
delete[]( list->selections );
19751980

1981+
// Clear child window pointers to prevent dangling pointer access
1982+
list->slider = NULL;
1983+
list->upButton = NULL;
1984+
list->downButton = NULL;
1985+
19761986
delete (ListboxData *)window->winGetUserData();
19771987
window->winSetUserData( NULL );
19781988
list = NULL;

0 commit comments

Comments
 (0)