From dabcb2e506a323759fd76066b81ca458829abe42 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Thu, 20 Feb 2025 21:17:55 -0600 Subject: [PATCH] Spreadsheet: Fixes for coverity defects Feb 2025 --- src/Mod/Spreadsheet/App/Cell.cpp | 2 +- src/Mod/Spreadsheet/App/DisplayUnit.h | 2 +- src/Mod/Spreadsheet/App/PropertySheet.cpp | 4 ++-- src/Mod/Spreadsheet/App/Sheet.cpp | 10 +++++++++- src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp | 2 +- src/Mod/Spreadsheet/Gui/ZoomableView.h | 4 ++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Mod/Spreadsheet/App/Cell.cpp b/src/Mod/Spreadsheet/App/Cell.cpp index a5a1ee2c11..d6695a3978 100644 --- a/src/Mod/Spreadsheet/App/Cell.cpp +++ b/src/Mod/Spreadsheet/App/Cell.cpp @@ -543,7 +543,7 @@ void Cell::setDisplayUnit(const std::string& unit) if (newDisplayUnit != displayUnit) { PropertySheet::AtomicPropertyChange signaller(*owner); - displayUnit = newDisplayUnit; + displayUnit = std::move(newDisplayUnit); setUsed(DISPLAY_UNIT_SET, !displayUnit.isEmpty()); setDirty(); diff --git a/src/Mod/Spreadsheet/App/DisplayUnit.h b/src/Mod/Spreadsheet/App/DisplayUnit.h index a5ec4011f6..d698f93deb 100644 --- a/src/Mod/Spreadsheet/App/DisplayUnit.h +++ b/src/Mod/Spreadsheet/App/DisplayUnit.h @@ -39,7 +39,7 @@ public: explicit DisplayUnit(const std::string _stringRep = "", const Base::Unit _unit = Base::Unit(), double _scaler = 0.0) - : stringRep(_stringRep) + : stringRep(std::move(_stringRep)) , unit(_unit) , scaler(_scaler) {} diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index 221a109788..7643c6dfd6 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -787,7 +787,7 @@ void PropertySheet::setAlias(CellAddress address, const std::string& alias) App::ObjectIdentifier key(owner, oldAlias); App::ObjectIdentifier value(owner, alias.empty() ? address.toString() : alias); - m[key] = value; + m[key] = std::move(value); owner->getDocument()->renameObjectIdentifiers(m); } @@ -1397,7 +1397,7 @@ void PropertySheet::addDependencies(CellAddress key) // Insert into maps propertyNameToCellMap[propName].insert(key); - cellToPropertyNameMap[key].insert(propName); + cellToPropertyNameMap[key].insert(std::move(propName)); } } } diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index f94a1d9642..b810357488 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -104,7 +104,15 @@ Sheet::Sheet() Sheet::~Sheet() { - clearAll(); + try { + clearAll(); + } + catch (boost::wrapexcept&) { + // Don't let an exception propagate out of a destructor (calls terminate()) + Base::Console().Error( + "clearAll() resulted in an exception when deleting the spreadsheet : %s\n", + *pcNameInDocument); + } } /** diff --git a/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp b/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp index 6e9463abd4..6df7a3a10c 100644 --- a/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp +++ b/src/Mod/Spreadsheet/Gui/DlgBindSheet.cpp @@ -191,7 +191,7 @@ void DlgBindSheet::accept() addr = std::string("<<") + copy + ">>"; } else { - addr = copy; + addr = std::move(copy); } }; diff --git a/src/Mod/Spreadsheet/Gui/ZoomableView.h b/src/Mod/Spreadsheet/Gui/ZoomableView.h index a95e34e156..886d2b23ec 100644 --- a/src/Mod/Spreadsheet/Gui/ZoomableView.h +++ b/src/Mod/Spreadsheet/Gui/ZoomableView.h @@ -68,9 +68,9 @@ private: QPointer stv; QGraphicsScene m_scene; - QGraphicsProxyWidget* qpw; + QGraphicsProxyWidget* qpw {nullptr}; - int m_zoomLevel; + int m_zoomLevel {100}; protected: void focusOutEvent(QFocusEvent* event) override;