From 02ede3cd8970c0a74f228df279ba207e63cbb277 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 5 Jul 2023 23:34:02 -0400 Subject: [PATCH] BUG: Catch nullptr trying to rename DataObject (#643) * BUG: Catch nullptr trying to rename DataObject --------- Signed-off-by: Michael Jackson --- src/complex/DataStructure/DataObject.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/complex/DataStructure/DataObject.cpp b/src/complex/DataStructure/DataObject.cpp index 4f448a1f84..fc4f4461eb 100644 --- a/src/complex/DataStructure/DataObject.cpp +++ b/src/complex/DataStructure/DataObject.cpp @@ -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(parentId)->contains(name); }); + + return !std::any_of(m_ParentList.cbegin(), m_ParentList.cend(), [dataStructPtr, name](IdType parentId) { + const auto* baseGroupPtr = dataStructPtr->getDataAs(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)