Handle NULL value properly.

pull/1/head
Nicholas Marriott 2007-10-04 22:18:48 +00:00
parent 26b340964a
commit c63d4ab80f
1 changed files with 17 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
/* $Id: cmd-set-option.c,v 1.4 2007-10-04 22:18:48 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -102,17 +102,24 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx)
return;
}
number = strtonum(data->value, 0, UINT_MAX, &errstr);
bool = -1;
if (number == 1 ||
strcmp(data->value, "on") == 0 || strcmp(data->value, "yes") == 0)
if (data->value != NULL) {
number = strtonum(data->value, 0, UINT_MAX, &errstr);
bool = -1;
if (number == 1 || strcmp(data->value, "on") == 0 ||
strcmp(data->value, "yes") == 0)
bool = 1;
if (number == 0 || strcmp(data->value, "off") == 0 ||
strcmp(data->value, "no") == 0)
bool = 0;
} else
bool = 1;
if (number == 0 ||
strcmp(data->value, "off") == 0 || strcmp(data->value, "no") == 0)
bool = 0;
if (strcmp(data->option, "prefix") == 0) {
if (data->value == NULL) {
ctx->error(ctx, "invalid value");
return;
}
key = key_string_lookup_string(data->value);
if (key == KEYC_NONE) {
ctx->error(ctx, "unknown key: %s", data->value);