Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(wwsaveload): init m_GenericUserData and iterate definitions by Count

Olcay Seygane30acf5e9398
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h
index 82ae60485..be1390f92 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definition.h
@@ -138,6 +138,7 @@ private:
inline
DefinitionClass::DefinitionClass (void)
: m_ID (0),
+ m_GenericUserData (0), // was left uninitialized, so Get_User_Data() read stack/heap garbage
m_SaveEnabled (true),
m_DefinitionMgrLink (-1)
{
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp
index f189f47f5..9d68acb18 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWSaveLoad/definitionmgr.cpp
@@ -246,7 +246,10 @@ DefinitionMgrClass::Find_Typed_Definition (const char *name, uint32 class_id, bo
DynamicVectorClass<DefinitionClass*>* defs = DefinitionHash->Get(lower_case_name);
if (defs) {
- for (int i=0;i<defs->Length();++i) {
+ // Count(), not Length(): Length() is the allocated capacity (10 after the
+ // first Add), so the original loop walked uninitialized slots and called
+ // Get_Class_ID() through garbage pointers.
+ for (int i=0;i<defs->Count();++i) {
DefinitionClass* curr_def=(*defs)[i];
WWASSERT(curr_def);
uint32 curr_class_id = curr_def->Get_Class_ID ();