From 3f4bdfdf613e17b6b8e5e5f7fb91a4a9578c85c3 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 28 Dec 2024 11:44:51 +0100 Subject: [PATCH] fix: Exception being thrown when getting version parts from invalid version --- .../source/helpers/semantic_version.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/libimhex/source/helpers/semantic_version.cpp b/lib/libimhex/source/helpers/semantic_version.cpp index 688b0208c..3df1c1ac6 100644 --- a/lib/libimhex/source/helpers/semantic_version.cpp +++ b/lib/libimhex/source/helpers/semantic_version.cpp @@ -39,15 +39,27 @@ namespace hex { } u32 SemanticVersion::major() const { - return std::stoul(m_parts[0]); + try { + return std::stoul(m_parts[0]); + } catch (...) { + return 0; + } } u32 SemanticVersion::minor() const { - return std::stoul(m_parts[1]); + try { + return std::stoul(m_parts[1]); + } catch (...) { + return 0; + } } u32 SemanticVersion::patch() const { - return std::stoul(m_parts[2]); + try { + return std::stoul(m_parts[2]); + } catch (...) { + return 0; + } } bool SemanticVersion::nightly() const {