CResFactory: Resolve use-after-move in AddToLoadList()

The behavior on the right hand side would occur before the actual
assignment, making the tag value invalidated. Instead, we copy the tag
before the move is performed to keep the data valid when inserting it
into the map.
This commit is contained in:
Lioncash 2020-03-07 03:56:12 -05:00
parent 4daa8ac374
commit 0a47e623fd
1 changed files with 2 additions and 1 deletions

View File

@ -7,7 +7,8 @@ namespace urde {
static logvisor::Module Log("CResFactory"); static logvisor::Module Log("CResFactory");
void CResFactory::AddToLoadList(SLoadingData&& data) { void CResFactory::AddToLoadList(SLoadingData&& data) {
m_loadMap[data.x0_tag] = m_loadList.insert(m_loadList.end(), std::move(data)); const SObjectTag tag = data.x0_tag;
m_loadMap.insert_or_assign(tag, m_loadList.insert(m_loadList.end(), std::move(data)));
} }
CFactoryFnReturn CResFactory::BuildSync(const SObjectTag& tag, const CVParamTransfer& xfer, CObjectReference* selfRef) { CFactoryFnReturn CResFactory::BuildSync(const SObjectTag& tag, const CVParamTransfer& xfer, CObjectReference* selfRef) {