]> jfr.im git - irc/weechat/weechat.git/commitdiff
core, plugins: set error to NULL before calling strtol()
authorSébastien Helleu <redacted>
Wed, 1 Nov 2023 08:53:38 +0000 (09:53 +0100)
committerSébastien Helleu <redacted>
Wed, 1 Nov 2023 08:53:38 +0000 (09:53 +0100)
This is not strictly necessary, just in case the function strtol() doesn't
update the pointer.

15 files changed:
src/core/hook/wee-hook-process.c
src/core/wee-command.c
src/core/wee-config-file.c
src/core/wee-eval.c
src/core/wee-string.c
src/gui/gui-buffer.c
src/gui/gui-chat.c
src/plugins/buflist/buflist-mouse.c
src/plugins/irc/irc-list.c
src/plugins/irc/irc-message.c
src/plugins/irc/irc-protocol.c
src/plugins/irc/irc-redirect.c
src/plugins/plugin-api-info.c
src/plugins/relay/relay-auth.c
src/plugins/xfer/xfer-network.c

index ccfb5f47d9cc9574750420b230a3573833c1060b..4240f9b4e0bd04d7a9c2c08aa175a1819151c443 100644 (file)
@@ -146,6 +146,7 @@ hook_process_hashtable (struct t_weechat_plugin *plugin,
         ptr_value = hashtable_get (options, "buffer_flush");
         if (ptr_value && ptr_value[0])
         {
+            error = NULL;
             number = strtol (ptr_value, &error, 10);
             if (error && !error[0]
                 && (number >= 1) && (number <= HOOK_PROCESS_BUFFER_SIZE))
index f0361db5845dc7e7aba44e7b6f9a5796930d1302..80a053e3eee5a9970703782ca885037037fa0704 100644 (file)
@@ -733,6 +733,7 @@ COMMAND_CALLBACK(buffer)
                     else
                     {
                         ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]);
+                        error = NULL;
                         (void) strtol (argv[i], &error, 10);
                         clear_number = (error && !error[0]);
                     }
@@ -968,6 +969,7 @@ COMMAND_CALLBACK(buffer)
                     ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]);
                     if (ptr_buffer)
                     {
+                        error = NULL;
                         (void) strtol (argv[i], &error, 10);
                         if (error && !error[0])
                         {
@@ -1006,6 +1008,7 @@ COMMAND_CALLBACK(buffer)
                     ptr_buffer = gui_buffer_search_by_number_or_name (argv[i]);
                     if (ptr_buffer)
                     {
+                        error = NULL;
                         (void) strtol (argv[i], &error, 10);
                         if (error && !error[0])
                         {
index 59551fff25f6018b246617fa276d33bd4f1aa2a0..c3619d839f5baf46cd6cf3257d9ab2573bb40a4e 100644 (file)
@@ -3258,6 +3258,7 @@ config_file_parse_version (const char *version)
     if (!version)
         return -1;
 
+    error = NULL;
     number = strtoll (version, &error, 10);
     if (!error || error[0])
         return -1;
index b5afac0de13843ae82c9e33a07eb6b40d2cca5c2..c2370b504ffe655ac6e805c49a9d50039901aaf1 100644 (file)
@@ -413,6 +413,7 @@ eval_string_cut (const char *text, int screen)
     if (!tmp)
         return strdup ("");
 
+    error = NULL;
     number = strtol (tmp, &error, 10);
     if (!error || error[0] || (number < 0))
     {
@@ -453,6 +454,7 @@ eval_string_repeat (const char *text)
     if (!tmp)
         return strdup ("");
 
+    error = NULL;
     number = strtol (tmp, &error, 10);
     if (!error || error[0] || (number < 0))
     {
@@ -538,6 +540,7 @@ eval_string_split (const char *text)
     }
     else
     {
+        error = NULL;
         number = strtol (str_number, &error, 10);
         if (!error || error[0] || (number == 0))
             goto end;
@@ -578,6 +581,7 @@ eval_string_split (const char *text)
             }
             else if (strncmp (list_flags[i], "max_items=", 10) == 0)
             {
+                error = NULL;
                 max_items = strtol (list_flags[i] + 10, &error, 10);
                 if (!error || error[0] || (max_items < 0))
                     goto end;
@@ -686,6 +690,7 @@ eval_string_split_shell (const char *text)
     }
     else
     {
+        error = NULL;
         number = strtol (str_number, &error, 10);
         if (!error || error[0] || (number == 0))
             goto end;
@@ -766,6 +771,7 @@ eval_string_regex_group (const char *text, struct t_eval_context *eval_context)
     }
     else
     {
+        error = NULL;
         number = strtol (text, &error, 10);
         if (!error || error[0])
             number = -1;
@@ -897,6 +903,7 @@ eval_string_base_encode (const char *text)
     if (!base)
         goto end;
 
+    error = NULL;
     number = strtol (base, &error, 10);
     if (!error || error[0])
         goto end;
@@ -946,6 +953,7 @@ eval_string_base_decode (const char *text)
     if (!base)
         goto end;
 
+    error = NULL;
     number = strtol (base, &error, 10);
     if (!error || error[0])
         goto end;
@@ -1087,6 +1095,7 @@ eval_string_random (const char *text)
     tmp = string_strndup (text, pos - text);
     if (!tmp)
         goto error;
+    error = NULL;
     min_number = strtoll (tmp, &error, 10);
     if (!error || error[0])
     {
@@ -1095,6 +1104,7 @@ eval_string_random (const char *text)
     }
     free (tmp);
 
+    error = NULL;
     max_number = strtoll (pos + 1, &error, 10);
     if (!error || error[0])
         goto error;
@@ -2616,6 +2626,7 @@ eval_expression (const char *expr, struct t_hashtable *pointers,
         ptr_value = hashtable_get (options, "debug");
         if (ptr_value && ptr_value[0])
         {
+            error = NULL;
             number = strtol (ptr_value, &error, 10);
             if (error && !error[0] && (number >= 1))
             {
index 7374f9fe9f46bb807044cfbd540b08022446e69f..f1969964872fa9d4ffc811b4b08a0fb195072df1 100644 (file)
@@ -3345,6 +3345,7 @@ string_parse_size (const char *size)
     if (!str_number)
         goto end;
 
+    error = NULL;
     number = strtoll (str_number, &error, 10);
     if (!error || error[0])
         goto end;
index 114902a520f950d119a4adfead527d0522b83e55..f89b553f2d1a77e6eb2bb93d2ca687ec093e78a8 100644 (file)
@@ -2213,6 +2213,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument)
     else if (argument[0] == '-')
     {
         /* move the unread marker N lines towards the first line */
+        error = NULL;
         number = strtol (argument, &error, 10);
         if (error && !error[0] && (number < 0))
         {
@@ -2240,6 +2241,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument)
     else if (argument[0] == '+')
     {
         /* move the unread marker N lines towards the last line */
+        error = NULL;
         number = strtol (argument, &error, 10);
         if (error && !error[0] && (number > 0))
         {
@@ -2265,6 +2267,7 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument)
     else
     {
         /* move the unread marker N lines from the end towards the first line */
+        error = NULL;
         number = strtol (argument, &error, 10);
         if (error && !error[0] && (number > 0))
         {
@@ -2953,6 +2956,7 @@ gui_buffer_search_by_number_or_name (const char *string)
 
     ptr_buffer = NULL;
 
+    error = NULL;
     number = strtol (string, &error, 10);
     if (error && !error[0])
     {
index b4471d59c69f34134ea7bc142e650ddf10bcadf6..5c4e1a0859731c0a0a5a0fa7482de022b673471a 100644 (file)
@@ -1079,6 +1079,7 @@ gui_chat_hsignal_quote_line_cb (const void *pointer, void *data,
         hashtable_get (hashtable, "_chat_line_date") : NULL;
     if (date)
     {
+        error = NULL;
         number = strtol (date, &error, 10);
         if (error && !error[0])
         {
index d8ade4e80cf9e292ff8d84abb754f89e5896d0e3..352e0bd8504ad697ed8933a165e97cc767e6ba3f 100644 (file)
@@ -62,6 +62,7 @@ buflist_focus_cb (const void *pointer, void *data, struct t_hashtable *info)
     ptr_bar_item_line = weechat_hashtable_get (info, "_bar_item_line");
     if (!ptr_bar_item_line)
         goto end;
+    error = NULL;
     item_line = strtol (ptr_bar_item_line, &error, 10);
     if (!error || error[0])
         goto end;
@@ -250,9 +251,11 @@ buflist_hsignal_cb (const void *pointer, void *data, const char *signal,
         return WEECHAT_RC_OK;
     ptr_buffer = (struct t_gui_buffer *)value;
 
+    error = NULL;
     number = strtol (ptr_number, &error, 10);
     if (!error || error[0])
         return WEECHAT_RC_OK;
+    error = NULL;
     number2 = strtol (ptr_number2, &error, 10);
     if (!error || error[0])
         return WEECHAT_RC_OK;
index c4c41ddd25e8aa6219d2f42209b1610d2e56fdc3..2d509753c87c269d767390bba602377421e0b47a 100644 (file)
@@ -281,6 +281,7 @@ irc_list_channel_match_filter (struct t_irc_server *server,
     else if (strncmp (server->list->filter, "u:>", 3) == 0)
     {
         /* filter by users (> N)*/
+        error = NULL;
         number = strtol (server->list->filter + 3, &error, 10);
         if (error && !error[0] && channel->users > (int)number)
             return 1;
@@ -288,6 +289,7 @@ irc_list_channel_match_filter (struct t_irc_server *server,
     else if (strncmp (server->list->filter, "u:<", 3) == 0)
     {
         /* filter by users (< N)*/
+        error = NULL;
         number = strtol (server->list->filter + 3, &error, 10);
         if (error && !error[0] && channel->users < (int)number)
             return 1;
@@ -295,6 +297,7 @@ irc_list_channel_match_filter (struct t_irc_server *server,
     else if (strncmp (server->list->filter, "u:", 2) == 0)
     {
         /* filter by users */
+        error = NULL;
         number = strtol (server->list->filter + 2, &error, 10);
         if (error && !error[0] && channel->users >= (int)number)
             return 1;
@@ -437,6 +440,7 @@ irc_list_parse_messages (struct t_irc_server *server, const char *output)
                     ptr_name++;
                 }
                 channel->name2 = strdup (ptr_name);
+                error = NULL;
                 number = strtol (params[2], &error, 10);
                 channel->users = (error && !error[0]) ? number : 0;
                 channel->topic = (num_params > 3) ?
index 4889dc7a11b50311903082ac5e1c4838873364e7..e85d7b14a7a1cc801f6ea09289f889c9058c0ace 100644 (file)
@@ -625,6 +625,7 @@ irc_message_parse_cap_multiline_value (struct t_irc_server *server,
     ptr_value = (const char *)weechat_hashtable_get (values, "max-bytes");
     if (ptr_value)
     {
+        error = NULL;
         number = strtol (ptr_value, &error, 10);
         if (error && !error[0])
             server->multiline_max_bytes = number;
@@ -633,6 +634,7 @@ irc_message_parse_cap_multiline_value (struct t_irc_server *server,
     ptr_value = (const char *)weechat_hashtable_get (values, "max-lines");
     if (ptr_value)
     {
+        error = NULL;
         number = strtol (ptr_value, &error, 10);
         if (error && !error[0])
             server->multiline_max_lines = number;
index 1da7c8cfd62dea9c51f0ed51476e7a91f5916c4c..345bcb61d7b3d8c770bd23089722760be9903658 100644 (file)
@@ -421,6 +421,7 @@ irc_protocol_parse_time (const char *time)
             pos = strchr (time2, ',');
             if (pos)
                 pos[0] = '\0';
+            error = NULL;
             value = strtol (time2, &error, 10);
             if (error && !error[0] && (value >= 0))
                 time_value = (int)value;
index 7102b4819e9b5ba23f8f3755788058d67e290cb9..71aff5cecedc348f1d5e64ed67618fa0706f95ce 100644 (file)
@@ -462,6 +462,7 @@ irc_redirect_new_with_commands (struct t_irc_server *server,
                     if (pos)
                     {
                         pos[0] = '\0';
+                        error = NULL;
                         value = strtol (pos + 1, &error, 10);
                         if (!error || error[0])
                             value = -1;
@@ -1309,6 +1310,7 @@ irc_redirect_pattern_hsignal_cb (const void *pointer, void *data,
     timeout = 0;
     if (str_timeout && str_timeout[0])
     {
+        error = NULL;
         number = (int)strtol (str_timeout, &error, 10);
         if (error && !error[0])
             timeout = number;
@@ -1379,6 +1381,7 @@ irc_redirect_command_hsignal_cb (const void *pointer, void *data,
     count = 1;
     if (str_count && str_count[0])
     {
+        error = NULL;
         number = (int)strtol (str_count, &error, 10);
         if (error && !error[0])
             count = number;
@@ -1387,6 +1390,7 @@ irc_redirect_command_hsignal_cb (const void *pointer, void *data,
     timeout = 0;
     if (str_timeout && str_timeout[0])
     {
+        error = NULL;
         number = (int)strtol (str_timeout, &error, 10);
         if (error && !error[0])
             timeout = number;
index 4d9f07b420f1e6b16215bb6369073b1fb6e7901b..8dc586e2dfbbd02b69931edb15f006e650cf134e 100644 (file)
@@ -877,6 +877,7 @@ plugin_api_info_nick_color_ignore_case_cb (const void *pointer, void *data,
     case_range = -1;
     if (num_items >= 2)
     {
+        error = NULL;
         number = strtol (items[1], &error, 10);
         if (error && !error[0])
             case_range = (int)number;
@@ -916,6 +917,7 @@ plugin_api_info_nick_color_name_ignore_case_cb (const void *pointer, void *data,
     case_range = -1;
     if (num_items >= 2)
     {
+        error = NULL;
         number = strtol (items[1], &error, 10);
         if (error && !error[0])
             case_range = (int)number;
index 57ace728cb63abc7329d2017131bf12ab9eeea13..11041241393749818a2be1f0ee12469ac865be3e 100644 (file)
@@ -247,6 +247,7 @@ relay_auth_parse_pbkdf2 (const char *parameters,
     }
 
     /* parameter 2: iterations */
+    error = NULL;
     *iterations = (int)strtol (argv[1], &error, 10);
     if (!error || error[0])
         *iterations = 0;
index 9eeabf904b6c03ee23b47d264ce18d25b5538284..8eac448d524a5c1e4f3e149915557fbcc293f381 100644 (file)
@@ -63,6 +63,7 @@ xfer_network_convert_integer_to_ipv4 (const char *str_address)
     if (!str_address || !str_address[0])
         return NULL;
 
+    error = NULL;
     number = strtoll (str_address, &error, 10);
     if (!error || error[0] || (number <= 0) || (number > UINT32_MAX))
         return NULL;