mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 06:46:38 +02:00
core: use util functions to parse integers in hook functions
This commit is contained in:
+5
-11
@@ -560,9 +560,7 @@ void
|
||||
hook_set (struct t_hook *hook, const char *property, const char *value)
|
||||
{
|
||||
ssize_t num_written;
|
||||
char *error;
|
||||
long number;
|
||||
int rc;
|
||||
int rc, number;
|
||||
|
||||
/* invalid hook? */
|
||||
if (!hook_valid (hook))
|
||||
@@ -605,22 +603,20 @@ hook_set (struct t_hook *hook, const char *property, const char *value)
|
||||
&& (hook->type == HOOK_TYPE_PROCESS)
|
||||
&& (HOOK_PROCESS(hook, child_pid) > 0))
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
if (!error || error[0])
|
||||
if (!util_parse_int (value, 10, &number))
|
||||
{
|
||||
/* not a number? look for signal by name */
|
||||
number = signal_search_name (value);
|
||||
}
|
||||
if (number >= 0)
|
||||
{
|
||||
rc = kill (HOOK_PROCESS(hook, child_pid), (int)number);
|
||||
rc = kill (HOOK_PROCESS(hook, child_pid), number);
|
||||
if (rc < 0)
|
||||
{
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError sending signal %d to pid %d: %s"),
|
||||
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
|
||||
(int)number,
|
||||
number,
|
||||
HOOK_PROCESS(hook, child_pid),
|
||||
strerror (errno));
|
||||
}
|
||||
@@ -633,9 +629,7 @@ hook_set (struct t_hook *hook, const char *property, const char *value)
|
||||
&& ((hook->type == HOOK_TYPE_COMMAND)
|
||||
|| (hook->type == HOOK_TYPE_COMMAND_RUN)))
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
if (error && !error[0])
|
||||
if (util_parse_int (value, 10, &number))
|
||||
{
|
||||
switch (hook->type)
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "../core-log.h"
|
||||
#include "../core-string.h"
|
||||
#include "../core-url.h"
|
||||
#include "../core-util.h"
|
||||
#include "../../gui/gui-chat.h"
|
||||
#include "../../plugins/plugin.h"
|
||||
|
||||
@@ -88,9 +89,9 @@ hook_process_hashtable (struct t_weechat_plugin *plugin,
|
||||
{
|
||||
struct t_hook *new_hook;
|
||||
struct t_hook_process *new_hook_process;
|
||||
char *stdout_buffer, *stderr_buffer, *error;
|
||||
char *stdout_buffer, *stderr_buffer;
|
||||
const char *ptr_value;
|
||||
long number;
|
||||
int number;
|
||||
|
||||
stdout_buffer = NULL;
|
||||
stderr_buffer = NULL;
|
||||
@@ -149,12 +150,10 @@ 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]
|
||||
if (util_parse_int (ptr_value, 10, &number)
|
||||
&& (number >= 1) && (number <= HOOK_PROCESS_BUFFER_SIZE))
|
||||
{
|
||||
new_hook_process->buffer_flush = (int)number;
|
||||
new_hook_process->buffer_flush = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user