]> jfr.im git - solanum.git/blobdiff - ircd/msgbuf.c
ircd: attach_conf: avoid clang static analysis warning
[solanum.git] / ircd / msgbuf.c
index 50538d27031d049c231bdedd9e4ebc1c0aab584d..9d63d109fa3c66bef846a628f62eb1d04e4c8443 100644 (file)
@@ -33,7 +33,7 @@ int
 msgbuf_parse(struct MsgBuf *msgbuf, char *line)
 {
        char *ch;
-       char *parv[MAXPARA];
+       char *parv[MAXPARA + 1];
        size_t n_para;
 
        /* skip any leading spaces */
@@ -78,6 +78,8 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
 
                        *ch++ = '\0';
                }
+               else
+                       ch = t;
        }
 
        /* skip any whitespace between tags and origin */
@@ -113,33 +115,22 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line)
        return 0;
 }
 
-static int
-msgbuf_has_matching_tags(struct MsgBuf *msgbuf, unsigned int capmask)
-{
-       for (size_t i = 0; i < msgbuf->n_tags; i++)
-       {
-               if ((msgbuf->tags[i].capmask & capmask) != 0)
-                       return 1;
-       }
-
-       return 0;
-}
-
 static void
 msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned int capmask)
 {
-       if (!msgbuf_has_matching_tags(msgbuf, capmask))
-               return;
-
-       *buf = '@';
+       bool has_tags = false;
 
        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);
 
@@ -151,7 +142,8 @@ msgbuf_unparse_tags(char *buf, size_t buflen, struct MsgBuf *msgbuf, unsigned in
                }
        }
 
-       rb_strlcat(buf, " ", buflen);
+       if (has_tags)
+               rb_strlcat(buf, " ", buflen);
 }
 
 void