提交 2f39df5b 编写于 作者: L Luiz Capitulino

qemu-option: parse_option_number(): use error_set()

Note that qemu_opt_parse() callers still expect automatic error reporting
with QError, so qemu_opts_parse() calls qerror_report_err() to keep the
same semantics.
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
Reviewed-By: NLaszlo Ersek <lersek@redhat.com>
上级 8be7e7e4
......@@ -186,7 +186,8 @@ static int parse_option_bool(const char *name, const char *value, bool *ret)
return 0;
}
static int parse_option_number(const char *name, const char *value, uint64_t *ret)
static void parse_option_number(const char *name, const char *value,
uint64_t *ret, Error **errp)
{
char *postfix;
uint64_t number;
......@@ -194,15 +195,13 @@ static int parse_option_number(const char *name, const char *value, uint64_t *re
if (value != NULL) {
number = strtoull(value, &postfix, 0);
if (*postfix != '\0') {
qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number");
return -1;
error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
return;
}
*ret = number;
} else {
qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a number");
return -1;
error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
}
return 0;
}
static int parse_option_size(const char *name, const char *value, uint64_t *ret)
......@@ -579,8 +578,11 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
static int qemu_opt_parse(QemuOpt *opt)
{
Error *local_err = NULL;
if (opt->desc == NULL)
return 0;
switch (opt->desc->type) {
case QEMU_OPT_STRING:
/* nothing */
......@@ -588,12 +590,22 @@ static int qemu_opt_parse(QemuOpt *opt)
case QEMU_OPT_BOOL:
return parse_option_bool(opt->name, opt->str, &opt->value.boolean);
case QEMU_OPT_NUMBER:
return parse_option_number(opt->name, opt->str, &opt->value.uint);
parse_option_number(opt->name, opt->str, &opt->value.uint,
&local_err);
break;
case QEMU_OPT_SIZE:
return parse_option_size(opt->name, opt->str, &opt->value.uint);
default:
abort();
}
if (error_is_set(&local_err)) {
qerror_report_err(local_err);
error_free(local_err);
return -1;
}
return 0;
}
static void qemu_opt_del(QemuOpt *opt)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册