-
Notifications
You must be signed in to change notification settings - Fork 74
[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
base: main
Are you sure you want to change the base?
[ZH] Check vector size before accessing first element in World Builder MapObjectProps and ScorchOptions #1117
Conversation
@@ -256,4 +256,9 @@ void ScorchOptions::getAllSelectedDicts(void) | |||
} | |||
m_allSelectedDicts.push_back(pMapObj->getProperties()); | |||
} | |||
} | |||
|
|||
Dict** ScorchOptions::getFrontSelectedDicts() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix function name and body.
Dict** ScorchOptions::getAllSelectedDictsData()
{
#if defined(USING_STLPORT) || __cplusplus < 201103L
return !m_allSelectedDicts.empty() ? &m_allSelectedDicts.front() : NULL;
#else
return m_allSelectedDicts.data();
#endif
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed and ported to Generals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@@ -1740,6 +1740,15 @@ void MapObjectProps::InitSound(void) | |||
|
|||
} // end InitSound | |||
|
|||
Dict** MapObjectProps::getAllSelectedDictsData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code placed at a consistent location with Generals?
Reproduction steps: Start World Builder (debug build) and tick "Enabled" in the "Object Properties" window. This will result in a debug assertion: "front() called on empty vector".
Notice how a pointer to the first element of
m_allSelectedDicts
is taken without checking whether the vector is empty or not (line 1436):GeneralsGameCode/GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp
Lines 1418 to 1441 in 51afe0c
I chose to not add size checks everywhere but keep the code functionally the same except calling front() on an empty vector. As long as the vector is empty, the code in
DictItemUndoable::DictItemUndoable
won't attempt to dereference the front pointer so it can beNULL
.Would need to be replicated in Generals.
TODO