From 528a8b5b46943a2e0d54d4d47e7d2890a48ccf89 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 {