Skip to content

Commit

Permalink
BUG: Catch nullptr trying to rename DataObject (#643)
Browse files Browse the repository at this point in the history
* BUG: Catch nullptr trying to rename DataObject

---------

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Jul 6, 2023
1 parent 6874864 commit 02ede3c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/complex/DataStructure/DataObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,31 @@ std::string DataObject::getName() const

bool DataObject::canRename(const std::string& name) const
{

if(name == getName())
{
return true;
}

if(!IsValidName(name))
{
return false;
}

auto dataStruct = getDataStructure();
if(dataStruct == nullptr)
const auto* dataStructPtr = getDataStructure();
if(dataStructPtr == nullptr)
{
return false;
}
return !std::any_of(m_ParentList.cbegin(), m_ParentList.cend(), [dataStruct, name](IdType parentId) { return dataStruct->getDataAs<BaseGroup>(parentId)->contains(name); });

return !std::any_of(m_ParentList.cbegin(), m_ParentList.cend(), [dataStructPtr, name](IdType parentId) {
const auto* baseGroupPtr = dataStructPtr->getDataAs<BaseGroup>(parentId);
if(baseGroupPtr == nullptr)
{
std::cout << "DataObject::canRename(name=" << name << ") cannot get baseGroup from parentId = " << parentId << std::endl;
}
return baseGroupPtr != nullptr && baseGroupPtr->contains(name);
});
}

bool DataObject::rename(const std::string& name)
Expand Down

0 comments on commit 02ede3c

Please sign in to comment.