summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/curses/gui-curses-bar-window.c43
-rw-r--r--src/gui/curses/gui-curses-chat.c43
-rw-r--r--src/gui/gtk/gui-gtk-chat.c9
-rw-r--r--src/plugins/aspell/weechat-aspell.c7
-rw-r--r--src/plugins/irc/irc-color.c16
-rw-r--r--src/plugins/scripts/script.c7
6 files changed, 85 insertions, 40 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c
index 1c297c70f..209ba57e2 100644
--- a/src/gui/curses/gui-curses-bar-window.c
+++ b/src/gui/curses/gui-curses-bar-window.c
@@ -156,7 +156,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
int hide_chars_if_scrolling)
{
int weechat_color, x_with_hidden, size_on_screen, fg, bg, low_char, hidden;
- int pair;
+ int pair, rc;
char str_fg[3], str_bg[3], str_pair[6], utf_char[16], *next_char, *output;
char *error;
@@ -190,9 +190,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
- fg);
+ rc = sscanf (str_fg, "%d", &fg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ fg);
+ }
string += 3;
}
break;
@@ -202,9 +205,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
str_bg[0] = string[1];
str_bg[1] = string[2];
str_bg[2] = '\0';
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
- bg);
+ rc = sscanf (str_bg, "%d", &bg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ bg);
+ }
string += 3;
}
break;
@@ -218,10 +224,16 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
str_bg[0] = string[4];
str_bg[1] = string[5];
str_bg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
- fg, bg);
+ rc = sscanf (str_fg, "%d", &fg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ rc = sscanf (str_bg, "%d", &bg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ fg, bg);
+ }
+ }
string += 6;
}
break;
@@ -291,9 +303,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
str_fg[0] = string[0];
str_fg[1] = string[1];
str_fg[2] = '\0';
- sscanf (str_fg, "%d", &weechat_color);
- gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
- weechat_color);
+ rc = sscanf (str_fg, "%d", &weechat_color);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ weechat_color);
+ }
string += 2;
}
break;
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index b4e26df86..9a5468e00 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -180,7 +180,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
const unsigned char *string, int apply_style)
{
char str_fg[3], str_bg[3], str_pair[6], *error;
- int weechat_color, fg, bg, pair;
+ int weechat_color, fg, bg, pair, rc;
while (string[0])
{
@@ -203,9 +203,12 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_fg[0] = string[1];
str_fg[1] = string[2];
str_fg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
- fg);
+ rc = sscanf (str_fg, "%d", &fg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
+ fg);
+ }
}
string += 3;
}
@@ -218,9 +221,12 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_bg[0] = string[1];
str_bg[1] = string[2];
str_bg[2] = '\0';
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
- bg);
+ rc = sscanf (str_bg, "%d", &bg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
+ bg);
+ }
}
string += 3;
}
@@ -237,10 +243,16 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_bg[0] = string[4];
str_bg[1] = string[5];
str_bg[2] = '\0';
- sscanf (str_fg, "%d", &fg);
- sscanf (str_bg, "%d", &bg);
- gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
- fg, bg);
+ rc = sscanf (str_fg, "%d", &fg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ rc = sscanf (str_bg, "%d", &bg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
+ fg, bg);
+ }
+ }
}
string += 6;
}
@@ -289,9 +301,12 @@ gui_chat_string_next_char (struct t_gui_window *window,
str_fg[0] = string[0];
str_fg[1] = string[1];
str_fg[2] = '\0';
- sscanf (str_fg, "%d", &weechat_color);
- gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
- weechat_color);
+ rc = sscanf (str_fg, "%d", &weechat_color);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
+ weechat_color);
+ }
}
string += 2;
}
diff --git a/src/gui/gtk/gui-gtk-chat.c b/src/gui/gtk/gui-gtk-chat.c
index 711ba8c83..950646583 100644
--- a/src/gui/gtk/gui-gtk-chat.c
+++ b/src/gui/gtk/gui-gtk-chat.c
@@ -189,7 +189,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
const unsigned char *string, int apply_style)
{
char str_fg[3];
- int weechat_color;
+ int weechat_color, rc;
while (string[0])
{
@@ -210,8 +210,11 @@ gui_chat_string_next_char (struct t_gui_window *window,
string += 2;
if (apply_style)
{
- sscanf (str_fg, "%d", &weechat_color);
- gui_chat_set_weechat_color (window, weechat_color);
+ rc = sscanf (str_fg, "%d", &weechat_color);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ gui_chat_set_weechat_color (window, weechat_color);
+ }
}
}
break;
diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c
index 498ac1183..698657293 100644
--- a/src/plugins/aspell/weechat-aspell.c
+++ b/src/plugins/aspell/weechat-aspell.c
@@ -676,7 +676,7 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
const char *color_normal, *color_error;
int utf8_char_int, char_size;
int length, index_result, length_word, word_ok;
- int length_color_normal, length_color_error;
+ int length_color_normal, length_color_error, rc;
/* make C compiler happy */
(void) data;
@@ -685,7 +685,10 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
if (!string || !string[0])
return NULL;
- sscanf (modifier_data, "%lx", &value);
+ rc = sscanf (modifier_data, "%lx", &value);
+ if ((rc == EOF) || (rc == 0))
+ return NULL;
+
buffer = (struct t_gui_buffer *)value;
if (!weechat_aspell_spellers)
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index b8dfd36b2..6afa011a1 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -65,7 +65,7 @@ irc_color_decode (const char *string, int keep_colors)
unsigned char *out, *ptr_string;
int out_length, length, out_pos;
char str_fg[3], str_bg[3], str_color[128];
- int fg, bg, bold, reverse, italic, underline;
+ int fg, bg, bold, reverse, italic, underline, rc;
out_length = (strlen (string) * 2) + 1;
out = malloc (out_length);
@@ -164,13 +164,19 @@ irc_color_decode (const char *string, int keep_colors)
bg = -1;
if (str_fg[0])
{
- sscanf (str_fg, "%d", &fg);
- fg %= IRC_NUM_COLORS;
+ rc = sscanf (str_fg, "%d", &fg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ fg %= IRC_NUM_COLORS;
+ }
}
if (str_bg[0])
{
- sscanf (str_bg, "%d", &bg);
- bg %= IRC_NUM_COLORS;
+ rc = sscanf (str_bg, "%d", &bg);
+ if ((rc != EOF) && (rc >= 1))
+ {
+ bg %= IRC_NUM_COLORS;
+ }
}
snprintf (str_color, sizeof (str_color),
"%s%s%s",
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index bcccfec89..8f36e2106 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -386,13 +386,16 @@ void *
script_str2ptr (const char *pointer_str)
{
long unsigned int value;
+ int rc;
if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[1] != 'x'))
return NULL;
- sscanf (pointer_str + 2, "%lx", &value);
+ rc = sscanf (pointer_str + 2, "%lx", &value);
+ if ((rc != EOF) && (rc >= 1))
+ return (void *)value;
- return (void *)value;
+ return NULL;
}
/*