From 90e4b4ed95430c3d7d184a61dc756d46c2ac2d13 Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Sun, 31 Jan 2010 21:51:59 +0000 Subject: [PATCH] Adding a bunch of memset's to menu/automap creations so we won't run into uninitialized variables --- CHANGELOG.txt | 1 + main/automap.c | 4 ++++ main/kconfig.c | 2 ++ main/newmenu.c | 8 ++++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c97f8d366..d50ddd978 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D2X-Rebirth Changelog -------- main/newmenu.c: Fix memory errors, but still dynamically allocate menu and lb so it doesn't have to stay in newmenu_do4 and newmenu_listbox1 respectively main/automap.c, main/game.c, main/game.h, main/multi.c, main/multi.h, main/net_ipx.c, main/net_udp.c, main/newmenu.c: Fix crashing when doing menus in multiplayer, don't let player move when in automap +main/automap.c, main/kconfig.c, main/newmenu.c: Adding a bunch of memset's to menu/automap creations so we won't run into uninitialized variables 20100130 -------- diff --git a/main/automap.c b/main/automap.c index cd1c5bc2f..da1941363 100644 --- a/main/automap.c +++ b/main/automap.c @@ -784,8 +784,12 @@ void do_automap( int key_code ) automap *am; MALLOC(am, automap, 1); + if (am) + { + memset(am, 0, sizeof(automap)); automap_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *)) automap_handler, am); + } if (automap_wind == NULL) { diff --git a/main/kconfig.c b/main/kconfig.c index 0093e85e0..5068a2ea8 100644 --- a/main/kconfig.c +++ b/main/kconfig.c @@ -1016,9 +1016,11 @@ void kconfig_sub(kc_item * items,int nitems, char *title) kc_menu *menu; MALLOC(menu, kc_menu, 1); + if (!menu) return; + memset(menu, 0, sizeof(kc_menu)); menu->time_stopped = 0; menu->items = items; menu->nitems = nitems; diff --git a/main/newmenu.c b/main/newmenu.c index 2148a6817..f82ce92ad 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1287,9 +1287,11 @@ int newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, int done = 0; MALLOC(menu, newmenu, 1); + if (!menu) return -1; - + + memset(menu, 0, sizeof(newmenu)); menu->scroll_offset = 0; menu->last_scroll_check = -1; menu->all_text = 0; @@ -1982,9 +1984,11 @@ int newmenu_listbox1( char * title, int nitems, char * items[], int allow_abort_ int done = 0; MALLOC(lb, listbox, 1); + if (!lb) return -1; - + + memset(lb, 0, sizeof(listbox)); newmenu_close(); lb->title = title;