1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: use util functions to parse integers in bar functions

This commit is contained in:
Sébastien Helleu
2026-04-05 16:53:05 +02:00
parent 5ed21d7dad
commit 3d7f988973
2 changed files with 14 additions and 27 deletions
+2 -6
View File
@@ -2153,7 +2153,6 @@ gui_bar_item_focus_buffer_nicklist_cb (const void *pointer,
const char *str_window, *str_buffer, *str_bar_item_line;
struct t_gui_window *window;
struct t_gui_buffer *buffer;
char *error;
/* make C compiler happy */
(void) pointer;
@@ -2162,6 +2161,8 @@ gui_bar_item_focus_buffer_nicklist_cb (const void *pointer,
str_bar_item_line = hashtable_get (info, "_bar_item_line");
if (!str_bar_item_line || !str_bar_item_line[0])
return NULL;
if (!util_parse_int (str_bar_item_line, 10, &bar_item_line))
return NULL;
/* get window */
str_window = hashtable_get (info, "_window");
@@ -2193,11 +2194,6 @@ gui_bar_item_focus_buffer_nicklist_cb (const void *pointer,
if (!buffer)
return NULL;
error = NULL;
bar_item_line = (int) strtol (str_bar_item_line, &error, 10);
if (!error || error[0])
return NULL;
i = 0;
ptr_group = NULL;
ptr_nick = NULL;
+12 -21
View File
@@ -39,6 +39,7 @@
#include "../core/core-infolist.h"
#include "../core/core-log.h"
#include "../core/core-string.h"
#include "../core/core-util.h"
#include "../plugins/plugin.h"
#include "gui-bar.h"
#include "gui-bar-item.h"
@@ -1018,9 +1019,7 @@ gui_bar_config_check_size (const void *pointer, void *data,
const char *value)
{
struct t_gui_bar *ptr_bar;
long number;
char *error;
int new_value, current_size;
int new_value, current_size, number;
/* make C compiler happy */
(void) pointer;
@@ -1032,30 +1031,26 @@ gui_bar_config_check_size (const void *pointer, void *data,
new_value = -1;
if (strncmp (value, "++", 2) == 0)
{
error = NULL;
number = strtol (value + 2, &error, 10);
if (error && !error[0])
if (util_parse_int (value + 2, 10, &number))
{
if ((number < 0) || (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_SIZE]) > INT_MAX - number))
return 0;
new_value = CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_SIZE]) + number;
}
}
else if (strncmp (value, "--", 2) == 0)
{
error = NULL;
number = strtol (value + 2, &error, 10);
if (error && !error[0])
if (util_parse_int (value + 2, 10, &number))
{
if ((number < 0) || (CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_SIZE]) < INT_MIN + number))
return 0;
new_value = CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_SIZE]) - number;
}
}
else
{
error = NULL;
number = strtol (value, &error, 10);
if (error && !error[0])
{
if (util_parse_int (value, 10, &number))
new_value = number;
}
}
if (new_value < 0)
return 0;
@@ -2062,9 +2057,8 @@ gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_window *window,
const char *scroll)
{
struct t_gui_bar_window *ptr_bar_win;
long number;
char *str, *error;
int length, add_x, add, percent, scroll_beginning, scroll_end;
char *str;
int length, add_x, add, percent, scroll_beginning, scroll_end, number;
if (!bar)
return 0;
@@ -2132,10 +2126,7 @@ gui_bar_scroll (struct t_gui_bar *bar, struct t_gui_window *window,
if (!str)
return 0;
error = NULL;
number = strtol (str, &error, 10);
if (!error || error[0] || (number <= 0))
if (!util_parse_int (str, 10, &number) || (number <= 0))
{
free (str);
return 0;