From d850e87567a79327526712dc987bf4f75f05e136 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 2 Mar 2025 21:16:01 -0600 Subject: [PATCH] Base: Coverity cleanup --- src/App/Branding.cpp | 2 +- src/App/ComplexGeoData.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/App/Branding.cpp b/src/App/Branding.cpp index ae9052d123..cea0497e0f 100644 --- a/src/App/Branding.cpp +++ b/src/App/Branding.cpp @@ -93,7 +93,7 @@ Branding::XmlConfig Branding::getUserDefines() const std::string name = child.localName().toLatin1().constData(); std::string value = child.text().toUtf8().constData(); if (std::ranges::find(filter, name) != filter.end()) { - cfg[name] = value; + cfg[name] = std::move(value); } child = child.nextSiblingElement(); } diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index b8a1c67c6a..f59bdc4329 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -653,8 +653,11 @@ void ComplexGeoData::RestoreDocFile(Base::Reader& reader) return; } } - std::size_t count = atoi(marker.c_str()); - restoreStream(reader, count); + auto count = atoll(marker.c_str()); // Try to prevent UB if the number is unreasonably large + if (count < 0 || count > std::numeric_limits::max()) { + FC_THROWM(Base::RuntimeError, "Failed to restore element map " << _persistenceName); + } + restoreStream(reader, static_cast(count)); } unsigned int ComplexGeoData::getMemSize() const