[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions
From: |
Laszlo Ersek |
Subject: |
Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions |
Date: |
Thu, 17 Jan 2013 19:29:17 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121116 Thunderbird/10.0.11 |
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,
(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:
"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>
- [Qemu-devel] [PATCH 0/8] -numa option parsing fixes (v3), Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 4/8] vl.c: Check for NUMA node limit inside numa_add(), Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 3/8] vl.c: Abort on unknown -numa option type, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 5/8] vl.c: numa_add(): Validate nodeid before using it, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 2/8] vl.c: Fix off-by-one bug when handling "-numa node" argument, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 6/8] vl.c: Use parse_uint_full() for NUMA nodeid, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 7/8] vl.c: Extract -numa "cpus" parsing to separate function, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 8/8] vl.c: validate -numa "cpus" parameter properly, Eduardo Habkost, 2013/01/16
- [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions, Eduardo Habkost, 2013/01/16
- Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions,
Laszlo Ersek <=
- Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions, Eduardo Habkost, 2013/01/17
- [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions, Eduardo Habkost, 2013/01/17
- Re: [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions, Laszlo Ersek, 2013/01/17
- Re: [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions, Eric Blake, 2013/01/17
- Re: [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions, Blue Swirl, 2013/01/17
- Re: [Qemu-devel] [PATCH 1/8 v4] cutils: unsigned int parsing functions, Eduardo Habkost, 2013/01/17
- Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions, Markus Armbruster, 2013/01/18