From 094311785e30c1b62d612727dbfc621c0aa29ba7 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 3 Sep 2013 00:20:17 -0400 Subject: [PATCH] fixed potential segfault --- src/prompt.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/prompt.c b/src/prompt.c index 99dd1ea..6e598c3 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -331,18 +331,24 @@ void cmd_mynick(ToxWindow *self, Tox *m, int argc, char **argv) void cmd_status(ToxWindow *self, Tox *m, int argc, char **argv) { - char *status, *status_text, *msg; - - /* check arguments */ - if (argv[2] && argv[2][0] != '\"') { - wprintw(self->window, "Messages must be enclosed in quotes.\n"); - return; - } if (argc != 1 && argc != 2) { wprintw(self->window, "Wrong number of arguments.\n"); return; } + char *status, *status_text; + char *msg = NULL; + + /* check arguments */ + if (argc == 2) { + msg = argv[2]; + if (msg[0] != '\"') { + wprintw(self->window, "Messages must be enclosed in quotes.\n"); + return; + } + } + + status = argv[1]; TOX_USERSTATUS status_kind; @@ -364,8 +370,6 @@ void cmd_status(ToxWindow *self, Tox *m, int argc, char **argv) wprintw(self->window, "Status set to: %s\n", status_text); tox_set_userstatus(m, status_kind); - msg = argv[2]; - if (msg != NULL) { msg[strlen(++msg)-1] = L'\0'; /* remove opening and closing quotes */ tox_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1);