Avoid strcat()
This patch removes strcat() and prevents possible buffer overflow introduced
in the previous changeset.
--- a/mcabber/src/commands.c Wed Jul 29 03:13:04 2009 +0400
+++ b/mcabber/src/commands.c Sun Oct 04 18:37:47 2009 +0200
@@ -1861,17 +1861,13 @@
} else if (style == style_compact) {
enum imrole role = buddy_getrole(bud, p_res->data);
enum imaffiliation affil = buddy_getaffil(bud, p_res->data);
-
- snprintf(buffer, 4095, "[%c] %s (", imstatus2char[rstatus],
- (char*)p_res->data);
-
- if (affil != affil_none) {
- strcat(buffer, straffil[affil]);
- strcat(buffer, "/");
- }
- strcat(buffer, strrole[role]);
- strcat(buffer, ")");
-
+ bool showaffil = (affil != affil_none);
+
+ snprintf(buffer, 4095, "[%c] %s (%s%s%s)",
+ imstatus2char[rstatus], (char*)p_res->data,
+ showaffil ? straffil[affil] : "\0",
+ showaffil ? "/" : "\0",
+ strrole[role]);
scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO, 0);
} else {
// (Style "normal", "detail" or "quiet")