ii

My fork of https://tools.suckless.org/ii/
git clone https://git.inz.fi/ii
Log | Files | Refs | README | LICENSE

commit 06b86af2291718112455397036f68c12dc58af0b
parent 286e3af1c71b91c676fdece9f435798f08ffb26b
Author: Santtu Lakkala <inz@inz.fi>
Date:   Wed,  9 Mar 2022 15:47:01 +0200

Skip unnecessary strlen()

Diffstat:
Mii.c | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/ii.c b/ii.c @@ -438,14 +438,14 @@ proc_channels_input(int ircfd, Channel *c, char *buf) proc_channels_privmsg(ircfd, c, buf); return; } + if (buf[1] == '\0') + return; msg[0] = '\0'; - if ((buflen = strlen(buf)) < 2) - return; if (buf[2] == ' ' || buf[2] == '\0') { switch (buf[1]) { case 'j': /* join */ - if (buflen < 3) + if (!buf[3]) return; if ((p = strchr(&buf[3], ' '))) /* password parameter */ *p = '\0'; @@ -465,21 +465,21 @@ proc_channels_input(int ircfd, Channel *c, char *buf) } break; case 't': /* topic */ - if (buflen >= 3) + if (buf[3]) snprintf(msg, sizeof(msg), "TOPIC %s :%s\r\n", c->name, &buf[3]); break; case 'a': /* away */ - if (buflen >= 3) { + if (buf[3]) { snprintf(msg, sizeof(msg), "-!- %s is away \"%s\"", nick, &buf[3]); channel_print(c, msg); } - if (buflen >= 3) + if (buf[3]) snprintf(msg, sizeof(msg), "AWAY :%s\r\n", &buf[3]); else snprintf(msg, sizeof(msg), "AWAY\r\n"); break; case 'n': /* change nick */ - if (buflen >= 3) { + if (buf[3]) { strlcpy(_nick, &buf[3], sizeof(_nick)); snprintf(msg, sizeof(msg), "NICK %s\r\n", &buf[3]); } @@ -487,7 +487,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf) case 'l': /* leave */ if (c == channelmaster) return; - if (buflen >= 3) + if (buf[3]) snprintf(msg, sizeof(msg), "PART %s :%s\r\n", c->name, &buf[3]); else snprintf(msg, sizeof(msg), @@ -497,7 +497,7 @@ proc_channels_input(int ircfd, Channel *c, char *buf) return; break; case 'q': /* quit */ - if (buflen >= 3) + if (buf[3]) snprintf(msg, sizeof(msg), "QUIT :%s\r\n", &buf[3]); else snprintf(msg, sizeof(msg),