From: Eric Blake <eblake@redhat.com>
To: David Hildenbrand <david@redhat.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v1 2/9] cutils: use qemu_strtod_finite() in do_strtosz()
Date: Thu, 15 Nov 2018 08:36:19 -0600 [thread overview]
Message-ID: <40ed700b-d0b1-2a03-eba9-4afa595de556@redhat.com> (raw)
In-Reply-To: <20181115140501.7872-3-david@redhat.com>
On 11/15/18 8:04 AM, David Hildenbrand wrote:
> Let's use the new function. In order to do so, we have to convert all
> users of qemu_strtosz*() to pass a "const char **end" ptr.
>
> We will now also reject "inf" properly.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> include/qemu/cutils.h | 6 +++---
> monitor.c | 2 +-
> tests/test-cutils.c | 14 +++++++-------
> util/cutils.c | 14 ++++++--------
> 4 files changed, 17 insertions(+), 19 deletions(-)
>
> +++ b/tests/test-cutils.c
> @@ -1950,7 +1950,7 @@ static void test_qemu_strtou64_full_max(void)
> static void test_qemu_strtosz_simple(void)
> {
> const char *str;
> - char *endptr = NULL;
> + const char *endptr = NULL;
...
> diff --git a/util/cutils.c b/util/cutils.c
Conversion of call sites is good (in fact, you could drop the ' = NULL'
initialization, since do_strtosz() guarantees it is set to something
sane even on error). But where's the added test coverage of rejecting
"inf" as a size?
> index 7868a683e8..dd61fb4558 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -206,19 +206,17 @@ static int64_t suffix_mul(char suffix, int64_t unit)
> * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
> * other error.
> */
> -static int do_strtosz(const char *nptr, char **end,
> +static int do_strtosz(const char *nptr, const char **end,
> const char default_suffix, int64_t unit,
> uint64_t *result)
> {
> int retval;
> - char *endptr;
> + const char *endptr;
> unsigned char c;
> int mul_required = 0;
> double val, mul, integral, fraction;
>
> - errno = 0;
> - val = strtod(nptr, &endptr);
> - if (isnan(val) || endptr == nptr || errno != 0) {
> + if (qemu_strtod_finite(nptr, &endptr, &val)) {
> retval = -EINVAL;
This slams -ERANGE failure into -EINVAL. Do we care? Or would it have
been better to just do:
retval = qemu_strtod_finite(...);
if (retval) {
goto out;
> goto out;
> }
> @@ -259,17 +257,17 @@ out:
More context:
out:
if (end) {
*end = endptr;
} else if (*endptr) {
retval = -EINVAL;
}
> return retval;
> }
Everything else looks okay.
Hmm - while touching this, is it worth making mul_required be a bool, to
match its use?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-11-15 14:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 14:04 [Qemu-devel] [PATCH v1 0/9] qapi: rewrite string-input-visitor David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 1/9] cutils: add qemu_strtod() and qemu_strtod_finite() David Hildenbrand
2018-11-15 14:23 ` Eric Blake
2018-11-15 16:22 ` Markus Armbruster
2018-11-15 17:25 ` David Hildenbrand
2018-11-15 18:02 ` Eric Blake
2018-11-15 21:57 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 2/9] cutils: use qemu_strtod_finite() in do_strtosz() David Hildenbrand
2018-11-15 14:36 ` Eric Blake [this message]
2018-11-15 16:41 ` Markus Armbruster
2018-11-15 17:59 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 3/9] qapi: use qemu_strtod_finite() in string-input-visitor David Hildenbrand
2018-11-15 14:37 ` Eric Blake
2018-11-15 14:39 ` David Hildenbrand
2018-11-15 16:48 ` Markus Armbruster
2018-11-15 21:54 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 4/9] qapi: use qemu_strtod_finite() in qobject-input-visitor David Hildenbrand
2018-11-15 14:45 ` Eric Blake
2018-11-16 14:46 ` Markus Armbruster
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 5/9] test-string-input-visitor: add more tests David Hildenbrand
2018-11-15 17:13 ` Eric Blake
2018-11-15 17:32 ` David Hildenbrand
2018-11-15 18:46 ` Markus Armbruster
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 6/9] qapi: rewrite string-input-visitor David Hildenbrand
2018-11-16 10:10 ` Markus Armbruster
2018-11-19 14:12 ` David Hildenbrand
2018-11-19 19:51 ` Markus Armbruster
2018-11-19 21:22 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 7/9] test-string-input-visitor: use virtual walk David Hildenbrand
2018-11-16 14:48 ` Markus Armbruster
2018-11-15 14:05 ` [Qemu-devel] [PATCH v1 8/9] test-string-input-visitor: split off uint64 list tests David Hildenbrand
2018-11-16 14:51 ` Markus Armbruster
2018-11-15 14:05 ` [Qemu-devel] [PATCH v1 9/9] test-string-input-visitor: add range overflow tests David Hildenbrand
2018-11-16 14:51 ` 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=40ed700b-d0b1-2a03-eba9-4afa595de556@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=david@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).