From d0f85a1b3fe04b66c67cb8e756c2442060a5e7f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C4=81nis=20R=C5=ABcis?= Date: Tue, 30 Mar 2010 20:40:50 +0300 Subject: [PATCH] IRC: clean up parsing sanity checks --- irc.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/irc.c b/irc.c index 91c1ee12..91faf7ee 100644 --- a/irc.c +++ b/irc.c @@ -163,14 +163,6 @@ static ircmessage_t *IRC_ParseMessage(const char *line) len = strcspn(line, " "); - /* TODO, is this really needed? */ - - if (line + len == line_end) - { - IRC_FreeMessage(msg); - return NULL; - } - msg->prefix = Z_Malloc(len + 1); memcpy(msg->prefix, line, len); msg->prefix[len] = 0; @@ -181,17 +173,23 @@ static ircmessage_t *IRC_ParseMessage(const char *line) else msg->prefix = NULL; + if (line == line_end) + { + IRC_FreeMessage(msg); + return NULL; + } + len = strcspn(line, " "); msg->command = Z_Malloc(len + 1); memcpy(msg->command, line, len); msg->command[len] = 0; - if (line + len != line_end) - { - line += len; - line += strspn(line, " "); + line += len; + line += strspn(line, " "); + if (line != line_end) + { len = line_end - line; msg->args = Z_Malloc(len + 1); -- 2.39.2