Skip to content

[ZH] Check vector size before accessing first element in World Builder MapObjectProps and ScorchOptions #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Generals/Code/Tools/WorldBuilder/include/ScorchOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ScorchOptions : public COptionsPanel, public PopupSliderOwner
void changeSize(void);
void changeScorch(void);
void getAllSelectedDicts(void);
Dict** getAllSelectedDictsData();

public:
static void update(void);
Expand Down
3 changes: 3 additions & 0 deletions Generals/Code/Tools/WorldBuilder/include/mapobjectprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class MapObjectProps : public COptionsPanel, public PopupSliderOwner
static MapObject *getSingleSelectedMapObject(void);
static void update(void);

private:
Dict** getAllSelectedDictsData();

};

//{{AFX_INSERT_LOCATION}}
Expand Down
13 changes: 11 additions & 2 deletions Generals/Code/Tools/WorldBuilder/src/ScorchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void ScorchOptions::changeScorch(void)

Dict newDict;
newDict.setInt(TheKey_scorchType, (Int)m_scorchtype);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
Expand All @@ -237,7 +237,7 @@ void ScorchOptions::changeSize(void)

Dict newDict;
newDict.setReal(TheKey_objectRadius, m_scorchsize);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
Expand All @@ -256,4 +256,13 @@ void ScorchOptions::getAllSelectedDicts(void)
}
m_allSelectedDicts.push_back(pMapObj->getProperties());
}
}

Dict** ScorchOptions::getAllSelectedDictsData()
{
#if defined(USING_STLPORT) || __cplusplus < 201103L
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
#else
return m_allSelectedDicts.data();
#endif
}
49 changes: 29 additions & 20 deletions Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ BOOL MapObjectProps::OnInitDialog()
}
}

Dict** MapObjectProps::getAllSelectedDictsData()
{
#if defined(USING_STLPORT) || __cplusplus < 201103L
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
#else
return m_allSelectedDicts.data();
#endif
}

void MapObjectProps::updateTheUI(void)
{
if (this != TheMapObjectProps) {
Expand Down Expand Up @@ -810,7 +819,7 @@ void MapObjectProps::_TeamToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setAsciiString(TheKey_originalOwner, AsciiString(buf));
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -827,7 +836,7 @@ void MapObjectProps::_NameToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setAsciiString(TheKey_objectName, cstr.GetBuffer(0));
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand Down Expand Up @@ -865,7 +874,7 @@ void MapObjectProps::_HealthToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setInt(TheKey_objectInitialHealth, value);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand Down Expand Up @@ -929,7 +938,7 @@ void MapObjectProps::_PrebuiltUpgradesToDict(void)

// Now, do the Undoable
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, NAMEKEY_INVALID, m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, NAMEKEY_INVALID, m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
}
Expand All @@ -944,7 +953,7 @@ void MapObjectProps::_EnabledToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectEnabled, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -961,7 +970,7 @@ void MapObjectProps::_ScriptToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setAsciiString(TheKey_objectScriptAttachment, AsciiString(buf));
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -977,7 +986,7 @@ void MapObjectProps::_IndestructibleToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectIndestructible, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -993,7 +1002,7 @@ void MapObjectProps::_UnsellableToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectUnsellable, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1010,7 +1019,7 @@ void MapObjectProps::_TargetableToDict()
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool( TheKey_objectTargetable, isChecked );
DictItemUndoable *pUndo = new DictItemUndoable( &m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size() );
DictItemUndoable *pUndo = new DictItemUndoable( getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size() );
pDoc->AddAndDoUndoable( pUndo );
REF_PTR_RELEASE( pUndo ); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1027,7 +1036,7 @@ void MapObjectProps::_PoweredToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectPowered, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand Down Expand Up @@ -1058,7 +1067,7 @@ void MapObjectProps::_AggressivenessToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setInt(TheKey_objectAggressiveness, value);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1082,7 +1091,7 @@ void MapObjectProps::_VisibilityToDict(void)
if (value != -1) {
newDict.setInt(TheKey_objectVisualRange, value);
}
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, TheKey_objectVisualRange, m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, TheKey_objectVisualRange, m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1103,7 +1112,7 @@ void MapObjectProps::_VeterancyToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setInt(TheKey_objectVeterancy, value);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1121,7 +1130,7 @@ void MapObjectProps::_WeatherToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setInt(TheKey_objectWeather, curSel);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1139,7 +1148,7 @@ void MapObjectProps::_TimeToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setInt(TheKey_objectTime, curSel);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1164,7 +1173,7 @@ void MapObjectProps::_ShroudClearingDistanceToDict(void)
if (value != -1) {
newDict.setInt(TheKey_objectShroudClearingDistance, value);
}
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, TheKey_objectShroudClearingDistance, m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, TheKey_objectShroudClearingDistance, m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1180,7 +1189,7 @@ void MapObjectProps::_RecruitableAIToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectRecruitableAI, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1196,7 +1205,7 @@ void MapObjectProps::_SelectableToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setBool(TheKey_objectSelectable, isChecked);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand All @@ -1219,7 +1228,7 @@ void MapObjectProps::_HPsToDict()
Dict newDict;

newDict.setInt(TheKey_objectMaxHPs, value);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
}
Expand All @@ -1242,7 +1251,7 @@ void MapObjectProps::_StoppingDistanceToDict(void)
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
Dict newDict;
newDict.setReal(TheKey_objectStoppingDistance, value);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
// Update is called by Do
Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/Tools/WorldBuilder/include/ScorchOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ScorchOptions : public COptionsPanel, public PopupSliderOwner
void changeSize(void);
void changeScorch(void);
void getAllSelectedDicts(void);
Dict** getAllSelectedDictsData();

public:
static void update(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class MapObjectProps : public COptionsPanel, public PopupSliderOwner
MapObjectProps & operator=( const MapObjectProps & other ); // Deliberately undefined
void updateTheUI(MapObject *pMapObj);
void InitSound(void);
Dict** getAllSelectedDictsData();
};

//{{AFX_INSERT_LOCATION}}
Expand Down
13 changes: 11 additions & 2 deletions GeneralsMD/Code/Tools/WorldBuilder/src/ScorchOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void ScorchOptions::changeScorch(void)

Dict newDict;
newDict.setInt(TheKey_scorchType, (Int)m_scorchtype);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
Expand All @@ -237,7 +237,7 @@ void ScorchOptions::changeSize(void)

Dict newDict;
newDict.setReal(TheKey_objectRadius, m_scorchsize);
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
pDoc->AddAndDoUndoable(pUndo);
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
Expand All @@ -256,4 +256,13 @@ void ScorchOptions::getAllSelectedDicts(void)
}
m_allSelectedDicts.push_back(pMapObj->getProperties());
}
}

Dict** ScorchOptions::getAllSelectedDictsData()
{
#if defined(USING_STLPORT) || __cplusplus < 201103L
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
#else
return m_allSelectedDicts.data();
#endif
}
Loading
Loading