]> jfr.im git - solanum.git/blobdiff - ircd/msgbuf.c
ircd: attach_conf: avoid clang static analysis warning
[solanum.git] / ircd / msgbuf.c
index ac7609a76a4601603cfa247aa1136416239d1c7a..9d63d109fa3c66bef846a628f62eb1d04e4c8443 100644 (file)
@@ -33,9 +33,8 @@ int
 msgbuf_parse(struct MsgBuf *msgbuf, char *line)
 {
        char *ch;
-       char *parv[MAXPARA];
+       char *parv[MAXPARA + 1];
        size_t n_para;
-       int i;
 
        /* skip any leading spaces */
        for (ch = line; *ch && *ch == ' '; ch++)
@@ -79,6 +78,8 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
 
                        *ch++ = '\0';
                }
+               else
+                       ch = t;
        }
 
        /* skip any whitespace between tags and origin */
@@ -108,7 +109,7 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
                return 1;
 
        msgbuf->cmd = parv[0];
-       for (i = 0; i < n_para; i++)
+       for (size_t i = 0; i < n_para; i++)
                msgbuf_append_para(msgbuf, parv[i]);
 
        return 0;
@@ -117,17 +118,19 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
 static void
 msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
-
-       *buf = '@';
+       bool has_tags = false;
 
-       for (i = 0; i < msgbuf->n_tags; i++)
+       for (size_t i = 0; i < msgbuf->n_tags; i++)
        {
                if ((msgbuf->tags[i].capmask & capmask) == 0)
                        continue;
 
-               if (i != 0)
+               if (has_tags) {
                        rb_strlcat(buf, ";", buflen);
+               } else {
+                       *buf = '@';
+                       has_tags = true;
+               }
 
                rb_strlcat(buf, msgbuf->tags[i].key, buflen);
 
@@ -139,20 +142,25 @@ msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned in
                }
        }
 
-       rb_strlcat(buf, " ", buflen);
+       if (has_tags)
+               rb_strlcat(buf, " ", buflen);
 }
 
-static void
+void
 msgbuf_unparse_prefix(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
-
        memset(buf, 0, buflen);
 
        if (msgbuf->n_tags > 0)
                msgbuf_unparse_tags(buf, buflen, msgbuf, capmask);
 
        rb_snprintf_append(buf, buflen, ":%s ", msgbuf->origin != NULL ? msgbuf->origin : me.name);
+
+       if (msgbuf->cmd != NULL)
+               rb_snprintf_append(buf, buflen, "%s ", msgbuf->cmd);
+
+       if (msgbuf->target != NULL)
+               rb_snprintf_append(buf, buflen, "%s ", msgbuf->target);
 }
 
 /*
@@ -164,11 +172,9 @@ msgbuf_unparse_prefix(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned
 int
 msgbuf_unparse(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       int i;
-
        msgbuf_unparse_prefix(buf, buflen, msgbuf, capmask);
 
-       for (i = 0; i < msgbuf->n_para; i++)
+       for (size_t i = msgbuf->cmd != NULL ? 0 : 1; i < msgbuf->n_para; i++)
        {
                if (i == (msgbuf->n_para - 1))
                {