Skip to content

Commit 19281c1

Browse files
authored
[GEN][ZH] Check vector size before accessing first element in World Builder's MapObjectProps and ScorchOptions (#1117)
1 parent a017743 commit 19281c1

File tree

8 files changed

+101
-63
lines changed

8 files changed

+101
-63
lines changed

Generals/Code/Tools/WorldBuilder/include/ScorchOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ScorchOptions : public COptionsPanel, public PopupSliderOwner
8080
void changeSize(void);
8181
void changeScorch(void);
8282
void getAllSelectedDicts(void);
83+
Dict** getAllSelectedDictsData();
8384

8485
public:
8586
static void update(void);

Generals/Code/Tools/WorldBuilder/include/mapobjectprops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class MapObjectProps : public COptionsPanel, public PopupSliderOwner
6565
// Implementation
6666
protected:
6767
void getAllSelectedDicts(void);
68+
Dict** getAllSelectedDictsData();
6869

6970
static MapObjectProps *TheMapObjectProps;
7071

Generals/Code/Tools/WorldBuilder/src/ScorchOptions.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void ScorchOptions::changeScorch(void)
222222

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

238238
Dict newDict;
239239
newDict.setReal(TheKey_objectRadius, m_scorchsize);
240-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
240+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
241241
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
242242
pDoc->AddAndDoUndoable(pUndo);
243243
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
@@ -256,4 +256,13 @@ void ScorchOptions::getAllSelectedDicts(void)
256256
}
257257
m_allSelectedDicts.push_back(pMapObj->getProperties());
258258
}
259+
}
260+
261+
Dict** ScorchOptions::getAllSelectedDictsData()
262+
{
263+
#if defined(USING_STLPORT) || __cplusplus < 201103L
264+
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
265+
#else
266+
return m_allSelectedDicts.data();
267+
#endif
259268
}

Generals/Code/Tools/WorldBuilder/src/mapobjectprops.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void MapObjectProps::_TeamToDict(void)
810810
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
811811
Dict newDict;
812812
newDict.setAsciiString(TheKey_originalOwner, AsciiString(buf));
813-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
813+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
814814
pDoc->AddAndDoUndoable(pUndo);
815815
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
816816
// Update is called by Do
@@ -827,7 +827,7 @@ void MapObjectProps::_NameToDict(void)
827827
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
828828
Dict newDict;
829829
newDict.setAsciiString(TheKey_objectName, cstr.GetBuffer(0));
830-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
830+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
831831
pDoc->AddAndDoUndoable(pUndo);
832832
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
833833
// Update is called by Do
@@ -865,7 +865,7 @@ void MapObjectProps::_HealthToDict(void)
865865
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
866866
Dict newDict;
867867
newDict.setInt(TheKey_objectInitialHealth, value);
868-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
868+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
869869
pDoc->AddAndDoUndoable(pUndo);
870870
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
871871
// Update is called by Do
@@ -929,7 +929,7 @@ void MapObjectProps::_PrebuiltUpgradesToDict(void)
929929

930930
// Now, do the Undoable
931931
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
932-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, NAMEKEY_INVALID, m_allSelectedDicts.size(), pDoc, true);
932+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, NAMEKEY_INVALID, m_allSelectedDicts.size(), pDoc, true);
933933
pDoc->AddAndDoUndoable(pUndo);
934934
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
935935
}
@@ -944,7 +944,7 @@ void MapObjectProps::_EnabledToDict(void)
944944
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
945945
Dict newDict;
946946
newDict.setBool(TheKey_objectEnabled, isChecked);
947-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
947+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
948948
pDoc->AddAndDoUndoable(pUndo);
949949
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
950950
// Update is called by Do
@@ -961,7 +961,7 @@ void MapObjectProps::_ScriptToDict(void)
961961
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
962962
Dict newDict;
963963
newDict.setAsciiString(TheKey_objectScriptAttachment, AsciiString(buf));
964-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
964+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
965965
pDoc->AddAndDoUndoable(pUndo);
966966
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
967967
// Update is called by Do
@@ -977,7 +977,7 @@ void MapObjectProps::_IndestructibleToDict(void)
977977
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
978978
Dict newDict;
979979
newDict.setBool(TheKey_objectIndestructible, isChecked);
980-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
980+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
981981
pDoc->AddAndDoUndoable(pUndo);
982982
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
983983
// Update is called by Do
@@ -993,7 +993,7 @@ void MapObjectProps::_UnsellableToDict(void)
993993
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
994994
Dict newDict;
995995
newDict.setBool(TheKey_objectUnsellable, isChecked);
996-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
996+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
997997
pDoc->AddAndDoUndoable(pUndo);
998998
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
999999
// Update is called by Do
@@ -1010,7 +1010,7 @@ void MapObjectProps::_TargetableToDict()
10101010
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
10111011
Dict newDict;
10121012
newDict.setBool( TheKey_objectTargetable, isChecked );
1013-
DictItemUndoable *pUndo = new DictItemUndoable( &m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size() );
1013+
DictItemUndoable *pUndo = new DictItemUndoable( getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size() );
10141014
pDoc->AddAndDoUndoable( pUndo );
10151015
REF_PTR_RELEASE( pUndo ); // belongs to pDoc now.
10161016
// Update is called by Do
@@ -1027,7 +1027,7 @@ void MapObjectProps::_PoweredToDict(void)
10271027
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
10281028
Dict newDict;
10291029
newDict.setBool(TheKey_objectPowered, isChecked);
1030-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
1030+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
10311031
pDoc->AddAndDoUndoable(pUndo);
10321032
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
10331033
// Update is called by Do
@@ -1058,7 +1058,7 @@ void MapObjectProps::_AggressivenessToDict(void)
10581058
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
10591059
Dict newDict;
10601060
newDict.setInt(TheKey_objectAggressiveness, value);
1061-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
1061+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
10621062
pDoc->AddAndDoUndoable(pUndo);
10631063
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
10641064
// Update is called by Do
@@ -1082,7 +1082,7 @@ void MapObjectProps::_VisibilityToDict(void)
10821082
if (value != -1) {
10831083
newDict.setInt(TheKey_objectVisualRange, value);
10841084
}
1085-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, TheKey_objectVisualRange, m_allSelectedDicts.size());
1085+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, TheKey_objectVisualRange, m_allSelectedDicts.size());
10861086
pDoc->AddAndDoUndoable(pUndo);
10871087
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
10881088
// Update is called by Do
@@ -1103,7 +1103,7 @@ void MapObjectProps::_VeterancyToDict(void)
11031103
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
11041104
Dict newDict;
11051105
newDict.setInt(TheKey_objectVeterancy, value);
1106-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
1106+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
11071107
pDoc->AddAndDoUndoable(pUndo);
11081108
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
11091109
// Update is called by Do
@@ -1121,7 +1121,7 @@ void MapObjectProps::_WeatherToDict(void)
11211121
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
11221122
Dict newDict;
11231123
newDict.setInt(TheKey_objectWeather, curSel);
1124-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
1124+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
11251125
pDoc->AddAndDoUndoable(pUndo);
11261126
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
11271127
// Update is called by Do
@@ -1139,7 +1139,7 @@ void MapObjectProps::_TimeToDict(void)
11391139
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
11401140
Dict newDict;
11411141
newDict.setInt(TheKey_objectTime, curSel);
1142-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
1142+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
11431143
pDoc->AddAndDoUndoable(pUndo);
11441144
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
11451145
// Update is called by Do
@@ -1164,7 +1164,7 @@ void MapObjectProps::_ShroudClearingDistanceToDict(void)
11641164
if (value != -1) {
11651165
newDict.setInt(TheKey_objectShroudClearingDistance, value);
11661166
}
1167-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, TheKey_objectShroudClearingDistance, m_allSelectedDicts.size());
1167+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, TheKey_objectShroudClearingDistance, m_allSelectedDicts.size());
11681168
pDoc->AddAndDoUndoable(pUndo);
11691169
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
11701170
// Update is called by Do
@@ -1180,7 +1180,7 @@ void MapObjectProps::_RecruitableAIToDict(void)
11801180
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
11811181
Dict newDict;
11821182
newDict.setBool(TheKey_objectRecruitableAI, isChecked);
1183-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
1183+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
11841184
pDoc->AddAndDoUndoable(pUndo);
11851185
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
11861186
// Update is called by Do
@@ -1196,7 +1196,7 @@ void MapObjectProps::_SelectableToDict(void)
11961196
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
11971197
Dict newDict;
11981198
newDict.setBool(TheKey_objectSelectable, isChecked);
1199-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
1199+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
12001200
pDoc->AddAndDoUndoable(pUndo);
12011201
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
12021202
// Update is called by Do
@@ -1219,7 +1219,7 @@ void MapObjectProps::_HPsToDict()
12191219
Dict newDict;
12201220

12211221
newDict.setInt(TheKey_objectMaxHPs, value);
1222-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
1222+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
12231223
pDoc->AddAndDoUndoable(pUndo);
12241224
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
12251225
}
@@ -1242,7 +1242,7 @@ void MapObjectProps::_StoppingDistanceToDict(void)
12421242
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
12431243
Dict newDict;
12441244
newDict.setReal(TheKey_objectStoppingDistance, value);
1245-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
1245+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size(), pDoc, true);
12461246
pDoc->AddAndDoUndoable(pUndo);
12471247
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
12481248
// Update is called by Do
@@ -1342,6 +1342,14 @@ void MapObjectProps::getAllSelectedDicts(void)
13421342
}
13431343
}
13441344

1345+
Dict** MapObjectProps::getAllSelectedDictsData()
1346+
{
1347+
#if defined(USING_STLPORT) || __cplusplus < 201103L
1348+
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
1349+
#else
1350+
return m_allSelectedDicts.data();
1351+
#endif
1352+
}
13451353

13461354
void MapObjectProps::GetPopSliderInfo(const long sliderID, long *pMin, long *pMax, long *pLineSize, long *pInitial)
13471355
{

GeneralsMD/Code/Tools/WorldBuilder/include/ScorchOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ScorchOptions : public COptionsPanel, public PopupSliderOwner
8080
void changeSize(void);
8181
void changeScorch(void);
8282
void getAllSelectedDicts(void);
83+
Dict** getAllSelectedDictsData();
8384

8485
public:
8586
static void update(void);

GeneralsMD/Code/Tools/WorldBuilder/include/mapobjectprops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class MapObjectProps : public COptionsPanel, public PopupSliderOwner
6868
// Implementation
6969
protected:
7070
void getAllSelectedDicts(void);
71+
Dict** getAllSelectedDictsData();
7172

7273
static MapObjectProps *TheMapObjectProps;
7374

GeneralsMD/Code/Tools/WorldBuilder/src/ScorchOptions.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void ScorchOptions::changeScorch(void)
222222

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

238238
Dict newDict;
239239
newDict.setReal(TheKey_objectRadius, m_scorchsize);
240-
DictItemUndoable *pUndo = new DictItemUndoable(&m_allSelectedDicts.front(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
240+
DictItemUndoable *pUndo = new DictItemUndoable(getAllSelectedDictsData(), newDict, newDict.getNthKey(0), m_allSelectedDicts.size());
241241
CWorldBuilderDoc* pDoc = CWorldBuilderDoc::GetActiveDoc();
242242
pDoc->AddAndDoUndoable(pUndo);
243243
REF_PTR_RELEASE(pUndo); // belongs to pDoc now.
@@ -256,4 +256,13 @@ void ScorchOptions::getAllSelectedDicts(void)
256256
}
257257
m_allSelectedDicts.push_back(pMapObj->getProperties());
258258
}
259+
}
260+
261+
Dict** ScorchOptions::getAllSelectedDictsData()
262+
{
263+
#if defined(USING_STLPORT) || __cplusplus < 201103L
264+
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
265+
#else
266+
return m_allSelectedDicts.data();
267+
#endif
259268
}

0 commit comments

Comments
 (0)