From: Amos Kong Date: Mon, 28 Apr 2014 05:53:49 +0000 (+0800) Subject: qapi: treat all negative return of strtosz_suffix() as error X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=cb45de6798956975c4b13a6233f7a00d2239b61a;p=qemu.git qapi: treat all negative return of strtosz_suffix() as error strtosz_suffix() might return negative error, this patch fixes the error handling. This patch also changes to handle error in the if statement rather than handle success specially, this will make this use of strtosz_suffix consistent with all other uses. Signed-off-by: Amos Kong Reviewed-by: Michael S. Tsirkin Signed-off-by: Luiz Capitulino --- diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 5d830a2b56..87c1c789c9 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -472,13 +472,14 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) val = strtosz_suffix(opt->str ? opt->str : "", &endptr, STRTOSZ_DEFSUFFIX_B); - if (val != -1 && *endptr == '\0') { - *obj = val; - processed(ov, name); + if (val < 0 || *endptr) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + "a size value representible as a non-negative int64"); return; } - error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - "a size value representible as a non-negative int64"); + + *obj = val; + processed(ov, name); }