qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: kwolf@redhat.com, ehabkost@redhat.com, mdroth@linux.vnet.ibm.com,
	qemu-devel@nongnu.org, stefanha@redhat.com,
	liguang <lig.fnst@cn.fujitsu.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] cutils:change strtosz_suffix_unit function
Date: Fri, 14 Dec 2012 14:45:53 +0100	[thread overview]
Message-ID: <20121214144553.4a1ca64c@thinkpad.mammed.net> (raw)
In-Reply-To: <87y5h0bzte.fsf@blackfin.pond.sub.org>

On Fri, 14 Dec 2012 13:09:17 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> liguang <lig.fnst@cn.fujitsu.com> writes:
> 
> > if value to be translated is larger than INT64_MAX,
> > this function will not be convenient for caller to
> > be aware of it, so change a little for this.
> >
> > Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> > ---
> >  cutils.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/cutils.c b/cutils.c
> > index 4f0692f..da05c9e 100644
> > --- a/cutils.c
> > +++ b/cutils.c
>    /*
>     * Convert string to bytes, allowing either B/b for bytes, K/k for KB,
>     * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned
>     * in *end, if not NULL. Return -1 on error.
>     */
Size is not the only user of it, this function is used to convert KHz,... in
target-i386/cpu.c, i.e. unit might be something else than 1024. That's why
there is question about generalizing strtosz_suffix_unit() in future instead of
duplicating suffixed int parsing. And specialization for size with
unit=1024 and enforcing limits could be made in strtosz_suffix() which is
used by current size users.


> > @@ -219,7 +219,7 @@ static int64_t suffix_mul(char suffix, int64_t unit)
> >  int64_t strtosz_suffix_unit(const char *nptr, char **end,
> >                              const char default_suffix, int64_t unit)
> >  {
> > -    int64_t retval = -1;
> > +    int64_t retval = EINVAL;
> >      char *endptr;
> >      unsigned char c;
> >      int mul_required = 0;
> > @@ -246,6 +246,7 @@ int64_t strtosz_suffix_unit(const char *nptr, char **end,
> >          goto fail;
> >      }
> >      if ((val * mul >= INT64_MAX) || val < 0) {
> > +        retval = ERANGE;
> >          goto fail;
> >      }
> >      retval = val * mul;
> 
> Your error codes aren't negative, and you failed to update the function
> comment!
Returning negative here is fine for now form target-i386/cpu.c pov.


-- 
Regards,
  Igor

  reply	other threads:[~2012-12-14 13:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14  4:08 [Qemu-devel] [PATCH 1/2] cutils:change strtosz_suffix_unit function liguang
2012-12-14  4:08 ` [Qemu-devel] [PATCH 2/2] qemu-img:report size overflow error message liguang
2012-12-14 12:19   ` Markus Armbruster
2012-12-17  0:34     ` li guang
2012-12-14 12:09 ` [Qemu-devel] [PATCH 1/2] cutils:change strtosz_suffix_unit function Markus Armbruster
2012-12-14 13:45   ` Igor Mammedov [this message]
2012-12-17  1:09     ` li guang
2012-12-17  0:35   ` li guang
  -- strict thread matches above, loose matches on Subject: below --
2012-12-07  3:49 [Qemu-devel] [ " liguang
2012-12-11  9:52 ` Stefan Hajnoczi
2012-12-11 15:06   ` Markus Armbruster
2012-12-12  0:58   ` li guang
2012-12-12  8:18     ` Stefan Hajnoczi
2012-12-12 10:12 ` Igor Mammedov
2012-12-13  8:03   ` Markus Armbruster
2012-12-13  9:11     ` Igor Mammedov
2012-12-13 12:09       ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121214144553.4a1ca64c@thinkpad.mammed.net \
    --to=imammedo@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lig.fnst@cn.fujitsu.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).