From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhQ3w-0001rZ-50 for qemu-devel@nongnu.org; Mon, 05 May 2014 17:04:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhQ3p-0003kO-T1 for qemu-devel@nongnu.org; Mon, 05 May 2014 17:04:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhQ3p-0003kI-M9 for qemu-devel@nongnu.org; Mon, 05 May 2014 17:04:29 -0400 Date: Mon, 5 May 2014 16:10:17 -0400 From: Luiz Capitulino Message-ID: <20140505161017.557b0f13@redhat.com> In-Reply-To: <1398664429-10682-1-git-send-email-akong@redhat.com> References: <1398664429-10682-1-git-send-email-akong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] qapi: treat all negative return of strtosz_suffix() as error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amos Kong Cc: mst@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com On Mon, 28 Apr 2014 13:53:49 +0800 Amos Kong wrote: > 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 Applied to the qmp branch, thanks. > --- > qapi/opts-visitor.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c > index 5d830a2..87c1c78 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); > } > >