diff options
author | Luiz Capitulino <lcapitulino@redhat.com> | 2012-03-21 14:37:44 -0300 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2012-06-04 13:49:34 -0300 |
commit | 2f39df5b0da6a030cc04c80e4e78ccd7002176b0 (patch) | |
tree | 92571fbb424d3664e1db32e75b319b2baee0901d /qemu-option.c | |
parent | 8be7e7e4c72c048b90e3482557954a24bba43ba7 (diff) |
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: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-By: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'qemu-option.c')
-rw-r--r-- | qemu-option.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/qemu-option.c b/qemu-option.c index 9f531c8d01..72dcb566d8 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -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) |