From 269dd686b3185a44f4ec83982eedb162f875228f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 10 Feb 2016 00:46:32 -0600 Subject: [PATCH] msgbuf: improve parse logic --- include/msgbuf.h | 4 +--- ircd/msgbuf.c | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/msgbuf.h b/include/msgbuf.h index 2771e0a09..801a54028 100644 --- a/include/msgbuf.h +++ b/include/msgbuf.h @@ -68,9 +68,7 @@ int msgbuf_vunparse_fmt(char *buf, struct MsgBuf *head, const char *fmt, va_list static inline void msgbuf_init(struct MsgBuf *msgbuf) { - msgbuf->n_tags = msgbuf->n_para = msgbuf->parselen = 0; - msgbuf->origin = NULL; - msgbuf->cmd = NULL; + memset(msgbuf, 0, sizeof(*msgbuf)); } static inline void diff --git a/ircd/msgbuf.c b/ircd/msgbuf.c index 860447880..e3f538924 100644 --- a/ircd/msgbuf.c +++ b/ircd/msgbuf.c @@ -48,7 +48,7 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line) ch = strchr(ch, ' '); if (ch != NULL) { - while (t < ch) + while (1) { char *next = strchr(t, ';'); char *eq = strchr(t, '='); @@ -63,7 +63,11 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line) *eq = '\0'; msgbuf_append_tag(msgbuf, t, eq); - t = next + 1; + + if (next != NULL) + t = next + 1; + else + break; } } } @@ -95,9 +99,7 @@ msgbuf_parse(struct MsgBuf *msgbuf, char *line) return 1; msgbuf->cmd = parv[0]; - msgbuf->n_para = n_para - 1; - - for (i = 1; i < n_para; i++) + for (i = 0; i < n_para; i++) msgbuf_append_para(msgbuf, parv[i]); return 0;