summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-11-14 20:16:12 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-11-14 20:16:12 +0100
commitbb0967075765620725499b8792f9b53056fce51f (patch)
treed30c0801da3155dfdea9c0fdcb7c9a4a781cf2e7
parent5328fdcc733143976e7fb2c8b36a328f90d82f41 (diff)
downloadweechat-bb0967075765620725499b8792f9b53056fce51f.zip
irc: add comments in function irc_color_decode
-rw-r--r--src/plugins/irc/irc-color.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index 6e72fd3d0..510dec15a 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -68,6 +68,10 @@ irc_color_decode (const char *string, int keep_colors)
const char *remapped_color;
int fg, bg, bold, reverse, italic, underline, rc;
+ /*
+ * create output string with size of length*2 (with min 128 bytes),
+ * this string will be realloc() later with a larger size if needed
+ */
out_length = (strlen (string) * 2) + 1;
if (out_length < 128)
out_length = 128;
@@ -75,6 +79,7 @@ irc_color_decode (const char *string, int keep_colors)
if (!out)
return NULL;
+ /* initialize attributes */
bold = 0;
reverse = 0;
italic = 0;
@@ -220,6 +225,10 @@ irc_color_decode (const char *string, int keep_colors)
}
break;
default:
+ /*
+ * we are not on an IRC color code, just copy the UTF-8 char
+ * into "str_to_add"
+ */
length = weechat_utf8_char_size ((char *)ptr_string);
if (length == 0)
length = 1;
@@ -228,17 +237,21 @@ irc_color_decode (const char *string, int keep_colors)
ptr_string += length;
break;
}
+ /* add "str_to_add" (if not empty) to "out" */
if (str_to_add[0])
{
+ /* if "out" is too small for adding "str_to_add", do a realloc() */
length_to_add = strlen (str_to_add);
- if (out_pos + length_to_add >= out_length)
+ if (out_pos + length_to_add + 1 > out_length)
{
+ /* try to double the size of "out" */
out_length *= 2;
out2 = realloc (out, out_length);
if (!out2)
return (char *)out;
out = out2;
}
+ /* add "str_to_add" to "out" */
memcpy (out + out_pos, str_to_add, length_to_add + 1);
out_pos += length_to_add;
}