commit dc445b6bb783f4e31c4007b264d5a04dc66c16a1
parent 2bbdf4b42b239e9d6715d09c2fecb59bc067efd7
Author: hhvn <dev@hhvn.uk>
Date: Tue, 16 Nov 2021 18:26:19 +0000
commands.c: don't segfault on /part and /join
Diffstat:
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/commands.c b/commands.c
@@ -67,6 +67,11 @@ command_quit(struct Server *server, char *str) {
void
command_join(struct Server *server, char *str) {
+ if (!str) {
+ ui_error("/join requires argument", NULL);
+ return;
+ }
+
if (strchr(config_gets("def.chantypes"), *str))
ircprintf(server, "JOIN %s\r\n", str);
else
@@ -76,11 +81,19 @@ command_join(struct Server *server, char *str) {
void
command_part(struct Server *server, char *str) {
- if (strchr(config_gets("def.chantypes"), *str))
- ircprintf(server, "PART %s\r\n", str);
+ char *channel;
+
+ channel = str ? str : selected.channel ? selected.channel->name : NULL;
+ if (!channel) {
+ ui_error("/part requires argument", NULL);
+ return;
+ }
+
+ if (strchr(config_gets("def.chantypes"), *channel))
+ ircprintf(server, "PART %s\r\n", channel);
else
- ircprintf(server, "PART #%s\r\n", str);
- handle_expect(server, Expect_join, str);
+ ircprintf(server, "PART #%s\r\n", channel);
+ handle_expect(server, Expect_join, channel);
}
void