From 94e5de4836b1d745a420a6946ebd683261ce74a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 15 Mar 2026 09:07:02 +0100 Subject: [PATCH] core: use function util_parse_int in function string_get_priority_and_name --- src/core/core-string.c | 13 ++++++------- tests/unit/core/test-core-string.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/core-string.c b/src/core/core-string.c index 34e3cf830..6ce8f17a1 100644 --- a/src/core/core-string.c +++ b/src/core/core-string.c @@ -55,6 +55,7 @@ #include "core-eval.h" #include "core-hashtable.h" #include "core-utf8.h" +#include "core-util.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" #include "../plugins/plugin.h" @@ -4439,8 +4440,8 @@ string_get_priority_and_name (const char *string, int *priority, const char **name, int default_priority) { - char *pos, *str_priority, *error; - long number; + char *pos, *str_priority; + int number; if (priority) *priority = default_priority; @@ -4456,17 +4457,15 @@ string_get_priority_and_name (const char *string, str_priority = string_strndup (string, pos - string); if (str_priority) { - error = NULL; - number = strtol (str_priority, &error, 10); - if (error && !error[0]) + if (util_parse_int (str_priority, 10, &number)) { if (priority) *priority = number; - if (name) - *name = pos + 1; } free (str_priority); } + if (name) + *name = pos + 1; } } diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index e00e1ef0a..aad2756eb 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -2971,11 +2971,11 @@ TEST(CoreString, GetPriorityAndName) LONGS_EQUAL(500, priority); STRCMP_EQUAL("", ptr_name); - /* "|" => (0, "") */ + /* "|" => (default_priority, "") */ priority = -1; ptr_name = NULL; string_get_priority_and_name (delimiter, &priority, &ptr_name, 500); - LONGS_EQUAL(0, priority); + LONGS_EQUAL(500, priority); STRCMP_EQUAL("", ptr_name); /* "test" => (default_priority, "test") */ @@ -2985,11 +2985,11 @@ TEST(CoreString, GetPriorityAndName) LONGS_EQUAL(500, priority); STRCMP_EQUAL("test", ptr_name); - /* "|test" => (0, "test") */ + /* "|test" => (default_priority, "test") */ priority = -1; ptr_name = NULL; string_get_priority_and_name (name_prio_empty, &priority, &ptr_name, 500); - LONGS_EQUAL(0, priority); + LONGS_EQUAL(500, priority); STRCMP_EQUAL("test", ptr_name); /* "1234|test" => (1234, "test") */