All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Cao jin <caoj.fnst@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: stefano.stabellini@eu.citrix.com
Subject: Re: [Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol
Date: Fri, 8 Jan 2016 10:35:36 -0700	[thread overview]
Message-ID: <568FF368.7080308@redhat.com> (raw)
In-Reply-To: <1452242274-8345-2-git-send-email-caoj.fnst@cn.fujitsu.com>

[-- Attachment #1: Type: text/plain, Size: 1661 bytes --]

On 01/08/2016 01:37 AM, Cao jin wrote:
> strtol() don`t guarantee errno to be ERANGE on overflow.

I stand slightly corrected: C99 requires ERANGE on overflow, but not
EINVAL; it is POSIX that adds EINVAL, but does not properly require it.
 At any rate, my main point was that errno is not always properly set by
all strtol implementations, and furthermore that you can't rely on it
being set to a sane value if you didn't pre-set it to 0.

> This wrapper returns either -EINVAL or the errno set by strtol()
> function (e.g -ERANGE).

The subject line doesn't start with a topic.  Maybe a better commit
message would be:

xen: Use qemu_strtoul instead of strtol

No need to roll our own (with slightly incorrect handling of errno),
when we can use the common version.

> 
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>  hw/xen/xen-host-pci-device.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)

>      buf[rc] = 0;
> -    value = strtol(buf, &endptr, base);
> -    if (endptr == buf || *endptr != '\n') {
> -        rc = -1;
> -    } else if ((value == LONG_MIN || value == LONG_MAX) && errno == ERANGE) {
> -        rc = -errno;
> -    } else {
> -        rc = 0;
> +    rc = qemu_strtoul(buf, &endptr, base, &value);

Why did you switch from strtol() to qemu_strtoul()?  Was signed parsing
incorrect, and unsigned parsing a bug fix?  If so, please mention it in
the commit message as intentional.  Otherwise, use qemu_strtol() (and
adjust the commit message accordingly).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-01-08 17:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-08  8:37 [Qemu-devel] [PATCH v4 0/5] Xen PCI passthru: Convert to realize() Cao jin
2016-01-08  8:37 ` [Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol Cao jin
2016-01-08 17:35   ` Eric Blake [this message]
2016-01-09  9:42     ` Cao jin
2016-01-08  8:37 ` [Qemu-devel] [PATCH v4 2/5] Add Error **errp for xen_host_pci_device_get() Cao jin
2016-01-08 22:50   ` Eric Blake
2016-01-09 10:49     ` Cao jin
2016-01-09 11:20     ` Cao jin
2016-01-08  8:37 ` [Qemu-devel] [PATCH v4 3/5] Add Error **errp for xen_pt_setup_vga() Cao jin
2016-01-08  8:37 ` [Qemu-devel] [PATCH v4 4/5] Add Error **errp for xen_pt_config_init() Cao jin
2016-01-08  8:37 ` [Qemu-devel] [PATCH v4 5/5] Xen PCI passthru: convert to realize() Cao jin

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=568FF368.7080308@redhat.com \
    --to=eblake@redhat.com \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.