From 37a0a0cb184f635e596acd9d1c211276b15310c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 20 Mar 2022 13:01:09 +0100 Subject: [PATCH] Use std::stol over C strtol on ClearScenery.cpp (#15549) Co-authored-by: Tulio Leao --- src/openrct2-ui/windows/ClearScenery.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index 8b59a55acb..b436af3ff5 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -140,15 +140,17 @@ public: if (widgetIndex != WIDX_PREVIEW || text.empty()) return; - char* end; - std::string textStr = std::string(text); - int32_t size = strtol(textStr.c_str(), &end, 10); - if (*end == '\0') + try { + int32_t size = std::stol(std::string(text)); size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE); gLandToolSize = size; Invalidate(); } + catch (const std::logic_error&) + { + // std::stol can throw std::out_of_range or std::invalid_argument + } } void OnUpdate() override