From 3a389752bd4dcdf54553a1ca580cd990f911e421 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Mon, 27 Feb 2023 19:43:23 +0100 Subject: [PATCH] catch exception in BSPF::stoi (fixes #958) --- src/common/bspf.hxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 9a7f217b0..72e38010c 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -197,10 +197,13 @@ namespace BSPF template inline int stoi(string_view s, const int defaultValue = 0) { - int i{}; - s = s.substr(s.find_first_not_of(" ")); - auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE); - return result.ec == std::errc() ? i : defaultValue; + try { + int i{}; + s = s.substr(s.find_first_not_of(" ")); + auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE); + return result.ec == std::errc() ? i : defaultValue; + } + catch(...) { return defaultValue; } } // Compare two strings (case insensitive)