diff --git a/src/Gui/WorkbenchManipulatorPython.cpp b/src/Gui/WorkbenchManipulatorPython.cpp index b85b49c99a..e7c220da41 100644 --- a/src/Gui/WorkbenchManipulatorPython.cpp +++ b/src/Gui/WorkbenchManipulatorPython.cpp @@ -26,8 +26,11 @@ #include "WorkbenchManipulatorPython.h" #include "MenuManager.h" #include "ToolBarManager.h" +#include #include +FC_LOG_LEVEL_INIT("WorkbenchManipulatorPython", true, true) + using namespace Gui; void WorkbenchManipulatorPython::installManipulator(const Py::Object& obj) @@ -153,6 +156,11 @@ void WorkbenchManipulatorPython::tryModifyMenuBar(const Py::Dict& dict, MenuItem std::string command = static_cast(Py::String(dict.getItem(remove))); if (auto par = menuBar->findParentOf(command)) { if (MenuItem* item = par->findItem(command)) { + if (item == menuBar) { + // Can't remove the menubar itself - Coverity issue 512853 + FC_WARN("Cannot remove top-level menubar"); + return; + } par->removeItem(item); delete item; // NOLINT } @@ -310,6 +318,11 @@ void WorkbenchManipulatorPython::tryModifyToolBar(const Py::Dict& dict, ToolBarI else { for (auto it : toolBar->getItems()) { if (ToolBarItem* item = it->findItem(command)) { + if (item == toolBar) { + // Can't remove the toolBar itself - Coverity issue 513838 + FC_WARN("Cannot remove top-level toolbar"); + return; + } it->removeItem(item); delete item; // NOLINT break;