From c6b1d82c70290faf051b82a9d2968f52a08c242e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 18 Feb 2024 23:31:43 +0000 Subject: [PATCH] hyprctl: more safety around stoull --- hyprctl/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index b1d89a8a..6126c514 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -86,7 +86,9 @@ std::vector instances() { data->id = el.path().string(); data->id = data->id.substr(data->id.find_last_of('/') + 1, data->id.find(".lock") - data->id.find_last_of('/') - 1); - data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1)); + try { + data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1)); + } catch (std::exception& e) { data->time = 0; } // read file std::ifstream ifs(el.path().string()); @@ -94,7 +96,9 @@ std::vector instances() { int i = 0; for (std::string line; std::getline(ifs, line); ++i) { if (i == 0) { - data->pid = std::stoull(line); + try { + data->pid = std::stoull(line); + } catch (std::exception& e) { data->pid = 0; } } else if (i == 1) { data->wlSocket = line; } else