From ce6a214ce13a8bf1dd211b4a2198ec4c8323f7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 20 Jun 2026 11:31:33 +0200 Subject: [PATCH] script: use util functions to parse integers --- src/plugins/script/script-command.c | 25 +++++++------------------ src/plugins/script/script-mouse.c | 17 +++++++---------- src/plugins/script/script-repo.c | 6 +----- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/plugins/script/script-command.c b/src/plugins/script/script-command.c index af06c2dfa..e5c753624 100644 --- a/src/plugins/script/script-command.c +++ b/src/plugins/script/script-command.c @@ -45,9 +45,7 @@ script_command_action (struct t_gui_buffer *buffer, { struct t_script_repo *ptr_script; char str_action[4096]; - long value; - char *error; - int quiet; + int quiet, value; if (arguments) { @@ -62,9 +60,7 @@ script_command_action (struct t_gui_buffer *buffer, arguments++; } } - error = NULL; - value = strtol (arguments, &error, 10); - if (error && !error[0]) + if (weechat_util_parse_int (arguments, 10, &value)) { ptr_script = script_repo_search_displayed_by_number (value); if (ptr_script) @@ -132,9 +128,8 @@ script_command_script (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - char *error, command[128]; - long value; - int line; + char command[128]; + int line, value; /* make C compiler happy */ (void) pointer; @@ -227,9 +222,7 @@ script_command_script (const void *pointer, void *data, } else { - error = NULL; - value = strtol (argv[2], &error, 10); - if (error && !error[0]) + if (weechat_util_parse_int (argv[2], 10, &value)) line = value; } if (line >= 0) @@ -248,9 +241,7 @@ script_command_script (const void *pointer, void *data, value = 1; if (argc > 2) { - error = NULL; - value = strtol (argv[2], &error, 10); - if (!error || error[0]) + if (!weechat_util_parse_int (argv[2], 10, &value)) value = 1; } if (script_buffer_detail_script) @@ -282,9 +273,7 @@ script_command_script (const void *pointer, void *data, value = 1; if (argc > 2) { - error = NULL; - value = strtol (argv[2], &error, 10); - if (!error || error[0]) + if (!weechat_util_parse_int (argv[2], 10, &value)) value = 1; } if (script_buffer_detail_script) diff --git a/src/plugins/script/script-mouse.c b/src/plugins/script/script-mouse.c index c292f3640..b7974731e 100644 --- a/src/plugins/script/script-mouse.c +++ b/src/plugins/script/script-mouse.c @@ -40,11 +40,10 @@ script_mouse_focus_chat_cb (const void *pointer, void *data, struct t_hashtable *info) { const char *buffer; - int rc; + int rc, y; unsigned long value; struct t_gui_buffer *ptr_buffer; - long x; - char *error, str_date[64]; + char str_date[64]; struct t_script_repo *ptr_script; struct tm *tm; @@ -72,15 +71,13 @@ script_mouse_focus_chat_cb (const void *pointer, void *data, ptr_script = script_buffer_detail_script; else { - error = NULL; - x = strtol (weechat_hashtable_get (info, "_chat_line_y"), &error, 10); - if (!error || error[0]) + if (!weechat_util_parse_int (weechat_hashtable_get (info, "_chat_line_y"), 10, &y) + || (y < 0)) + { return info; + } - if (x < 0) - return info; - - ptr_script = script_repo_search_displayed_by_number (x); + ptr_script = script_repo_search_displayed_by_number (y); if (!ptr_script) return info; } diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index 4cbb1704e..3ffbc2681 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -1312,11 +1312,7 @@ script_repo_file_read (int quiet) script->url = strdup (value); else if (strcmp (name, "popularity") == 0) { - error = NULL; - script->popularity = (int)strtol (value, - &error, - 10); - if (!error || error[0]) + if (!weechat_util_parse_int (value, 10, &(script->popularity))) script->popularity = 0; } else if (strcmp (name, "added") == 0)