Update workspaces.cpp

Fix unchecked string to int conversion of workspace name (which can be a string)
Closes #2501
This commit is contained in:
Roberto Previdi 2023-09-13 18:20:13 +02:00 committed by GitHub
parent a90e275d5e
commit 69736d68aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 2 deletions

View File

@ -439,7 +439,6 @@ void Workspaces::sort_workspaces() {
// Helper comparisons // Helper comparisons
auto is_id_less = a->id() < b->id(); auto is_id_less = a->id() < b->id();
auto is_name_less = a->name() < b->name(); auto is_name_less = a->name() < b->name();
auto is_number_less = std::stoi(a->name()) < std::stoi(b->name());
switch (sort_by_) { switch (sort_by_) {
case SORT_METHOD::ID: case SORT_METHOD::ID:
@ -448,7 +447,7 @@ void Workspaces::sort_workspaces() {
return is_name_less; return is_name_less;
case SORT_METHOD::NUMBER: case SORT_METHOD::NUMBER:
try { try {
return is_number_less; return std::stoi(a->name()) < std::stoi(b->name());
} catch (const std::invalid_argument &) { } catch (const std::invalid_argument &) {
// Handle the exception if necessary. // Handle the exception if necessary.
break; break;