From: Cao jin <caoj.fnst@cn.fujitsu.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, stefano.stabellini@eu.citrix.com
Subject: Re: [Qemu-devel] [PATCH v4 1/5] Use qemu_strtoul instead of strtol
Date: Sat, 9 Jan 2016 17:42:13 +0800 [thread overview]
Message-ID: <5690D5F5.2010508@cn.fujitsu.com> (raw)
In-Reply-To: <568FF368.7080308@redhat.com>
On 01/09/2016 01:35 AM, Eric Blake wrote:
> 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.
>
Got you:)
>> 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.
>
ok, looks good.
>>
>> 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).
>
Yes, I should mention it, sorry for forgetting to explain it. Because
what it want to read from host are values in pci device config space,
which are non-negative, like "vendor ID", "device ID", "class code",
etc. so unsigned parsing seems more suitable in this case. we can tell
it also from the local variable "unsigned long value;"
--
Yours Sincerely,
Cao jin
next prev parent reply other threads:[~2016-01-09 9:39 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
2016-01-09 9:42 ` Cao jin [this message]
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=5690D5F5.2010508@cn.fujitsu.com \
--to=caoj.fnst@cn.fujitsu.com \
--cc=eblake@redhat.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.