diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-11-23 21:25:41 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-11-23 21:25:41 +0100 |
commit | 21aef706cdf0a7fd4ef19a0ac869efc3e3d96d2e (patch) | |
tree | bd856547504917a472435fd512cb68658031b468 | |
parent | 345bdddf62ab12499c3b7abfdb89ae080d227224 (diff) | |
download | weechat-21aef706cdf0a7fd4ef19a0ac869efc3e3d96d2e.zip |
core: allocate dynamic string size for colors
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index dfd8ad5ec..61b423805 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -565,6 +565,8 @@ gui_color_get_name (int num_color) void gui_color_build (int number, int foreground, int background) { + char str_color[128]; + if (foreground < 0) foreground = 0; if (background < 0) @@ -576,7 +578,6 @@ gui_color_build (int number, int foreground, int background) gui_color[number] = malloc (sizeof (*gui_color[number])); if (!gui_color[number]) return; - gui_color[number]->string = malloc (4); } /* set foreground and attributes */ @@ -599,12 +600,10 @@ gui_color_build (int number, int foreground, int background) gui_color[number]->background = gui_weechat_colors[background & GUI_COLOR_EXTENDED_MASK].background; /* set string */ - if (gui_color[number]->string) - { - snprintf (gui_color[number]->string, 4, - "%c%02d", - GUI_COLOR_COLOR_CHAR, number); - } + snprintf (str_color, sizeof (str_color), + "%c%02d", + GUI_COLOR_COLOR_CHAR, number); + gui_color[number]->string = strdup (str_color); } /* |