From 0f793ff4aa7a39b0e2090bf3c0189eb2593a6ecf Mon Sep 17 00:00:00 2001 From: Cyan Date: Sat, 22 Feb 2025 16:23:23 +0200 Subject: [PATCH 1/2] Less crash-prone monitor config parser --- src/config/ConfigManager.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 9b547ffbb75..c3cab388efc 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1946,11 +1946,17 @@ std::optional CConfigManager::handleMonitor(const std::string& comm error += "invalid resolution "; newrule.resolution = Vector2D(); } else { - newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x'))); - newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@'))); + try { + newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x'))); + newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@'))); - if (ARGS[1].contains("@")) - newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1)); + if (ARGS[1].contains("@")) + newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1)); + } + catch (...) { + error += "invalid resolution "; + newrule.resolution = Vector2D(); + } } } From 5b58ec2ae65886224cef4a3eb618c7fa151bb3b8 Mon Sep 17 00:00:00 2001 From: Cyan Date: Sun, 23 Feb 2025 22:15:01 +0200 Subject: [PATCH 2/2] clang-format --- src/config/ConfigManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c3cab388efc..caa82871a48 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1952,8 +1952,7 @@ std::optional CConfigManager::handleMonitor(const std::string& comm if (ARGS[1].contains("@")) newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1)); - } - catch (...) { + } catch (...) { error += "invalid resolution "; newrule.resolution = Vector2D(); }