From d26b84df3fbc4fbda4a4b67b77c800ac8942613f Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 25 Feb 2023 16:57:30 -0600 Subject: [PATCH] Gui: Eliminate variable reuse Coverity complains about USE_AFTER_FREE here, and it was difficult to reason about the code. To help address this, use different variables for the different parameter groups. --- src/Gui/Workbench.cpp | 29 ++++++++++++++--------------- src/Gui/Workbench.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index a010204dbd..714f3ab3a5 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -226,14 +226,15 @@ void Workbench::setName(const std::string& name) void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const { std::string name = this->name(); - ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") - ->GetGroup("Workbench"); + const auto workbenchGroup { + App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench") + }; // workbench specific custom toolbars - if (hGrp->HasGroup(name.c_str())) { - hGrp = hGrp->GetGroup(name.c_str()); - if (hGrp->HasGroup(toolbar)) { - hGrp = hGrp->GetGroup(toolbar); - setupCustomToolbars(root, hGrp); + if (workbenchGroup->HasGroup(name.c_str())) { + const auto customGroup = workbenchGroup->GetGroup(name.c_str()); + if (customGroup->HasGroup(toolbar)) { + const auto customToolbarGroup = customGroup->GetGroup(toolbar); + setupCustomToolbars(root, customToolbarGroup); } } @@ -243,18 +244,16 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) cons } // application-wide custom toolbars - hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") - ->GetGroup("Workbench"); - if (hGrp->HasGroup("Global")) { - hGrp = hGrp->GetGroup("Global"); - if (hGrp->HasGroup(toolbar)) { - hGrp = hGrp->GetGroup(toolbar); - setupCustomToolbars(root, hGrp); + if (workbenchGroup->HasGroup("Global")) { + const auto globalGroup = workbenchGroup->GetGroup("Global"); + if (globalGroup->HasGroup(toolbar)) { + const auto customToolbarGroup = globalGroup->GetGroup(toolbar); + setupCustomToolbars(root, customToolbarGroup); } } } -void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference& hGrp) const +void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference hGrp) const { std::vector > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); diff --git a/src/Gui/Workbench.h b/src/Gui/Workbench.h index 6e40ae6abd..d6e3ccc3c1 100644 --- a/src/Gui/Workbench.h +++ b/src/Gui/Workbench.h @@ -130,7 +130,7 @@ private: * a ToolBarItem tree structure. */ void setupCustomToolbars(ToolBarItem* root, const char* toolbar) const; - void setupCustomToolbars(ToolBarItem* root, const Base::Reference& hGrp) const; + void setupCustomToolbars(ToolBarItem* root, const Base::Reference hGrp) const; void setupCustomShortcuts() const; private: