qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions
Date: Thu, 17 Jan 2013 16:50:42 -0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Jan 17, 2013 at 07:29:17PM +0100, Laszlo Ersek wrote:
> On 01/16/13 19:28, Eduardo Habkost wrote:
> 
> > +static void test_parse_uint_negative(void)
> > +{
> > +    unsigned long long i = 999;
> > +    char f = 'X';
> > +    char *endptr = &f;
> > +    const char *str = " \t -321";
> > +    int r;
> > +
> > +    r = parse_uint(str, &i, &endptr, 0);
> > +
> > +    g_assert_cmpint(r, ==, -ERANGE);
> > +    g_assert_cmpint(i, ==, 0);
> > +    g_assert(endptr == str + 3);
> > +}
> 
> I think it would be more true to the strtol() family if in this case
> 
> (a) we reported -EINVAL (invalid subject sequence) -- but I certainly
> don't insist on that,

It makes sense, as we didn't consume any number and simply aborted
parsing as soon as '-' was found.

> 
> (b) and, independently,
> 
> (b1) we either consumed all of the whitespace sequence *and* the subject
> sequence (which would be consistent with ERANGE; see
> test_parse_uint_overflow()),
> 
> (b2) or we didn't consume anything (not even part of the whitespace
> sequence). This would be easy to implement and also consistent with the
> strtol() family's behavior when it sees an invalid subject sequence:

This makes sense as well, especially if we return -EINVAL.

I will submit a new version of just this patch. Thanks!

> 
> "If the subject sequence is empty or does not have the expected form, no
> conversion is performed; the value of /str/ is stored in the object
> pointed to by /endptr/, provided that /endptr/ is not a null pointer."
> 
> But I don't insist on (b) either :)
> 
> Reviewed-by: Laszlo Ersek <address@hidden>


-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]