From f1774f1a3bfdf9b124e708014e8caf3a4f764ce5 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 11 May 2001 18:44:51 +0000 Subject: [PATCH] cmd_get_params() crashed in some conditions git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1489 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/commands.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index f6d71397..b6fb8a74 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -649,6 +649,7 @@ static char *get_optional_channel(CHANNEL_REC *active_channel, char **data) int cmd_get_params(const char *data, gpointer *free_me, int count, ...) { + CHANNEL_REC *chanrec; CMD_TEMP_REC *rec; GHashTable **opthash; char **str, *arg, *datad; @@ -665,6 +666,10 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...) datad = rec->data; error = FALSE; + + chanrec = (count & PARAM_FLAG_OPTCHAN) == 0 ? NULL: + (CHANNEL_REC *) va_arg(args, CHANNEL_REC *); + if (count & PARAM_FLAG_OPTIONS) { arg = (char *) va_arg(args, char *); opthash = (GHashTable **) va_arg(args, GHashTable **); @@ -683,14 +688,11 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...) cnt = PARAM_WITHOUT_FLAGS(count); if (count & PARAM_FLAG_OPTCHAN) { /* optional channel as first parameter */ - CHANNEL_REC *chanrec; - - chanrec = (CHANNEL_REC *) va_arg(args, CHANNEL_REC *); - arg = get_optional_channel(chanrec, &datad); + arg = get_optional_channel(chanrec, &datad); str = (char **) va_arg(args, char **); if (str != NULL) *str = arg; - cnt--; + cnt--; } while (cnt-- > 0) {