From: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
To: Max Reitz <mreitz@redhat.com>, Eric Blake <eblake@redhat.com>,
qemu devel <qemu-devel@nongnu.org>,
Alberto Garcia <berto@igalia.com>, Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu block <qemu-block@nongnu.org>,
Jiang Yunhong <yunhong.jiang@intel.com>,
Dong Eddie <eddie.dong@intel.com>,
Markus Armbruster <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Gonglei <arei.gonglei@huawei.com>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: Re: [Qemu-devel] [PATCH v10 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Date: Tue, 8 Mar 2016 10:57:50 +0800 [thread overview]
Message-ID: <56DE3FAE.6000305@cn.fujitsu.com> (raw)
In-Reply-To: <56DDA630.4000409@redhat.com>
On 03/08/2016 12:02 AM, Max Reitz wrote:
> On 07.03.2016 17:02, Eric Blake wrote:
>> On 03/05/2016 11:13 AM, Max Reitz wrote:
>>
>>>> + index = atoi(child->name + 9);
>>>
>>> Optional: Assert absence of an error:
>>>
>>
>> Indeed, atoi() is worthless, because it cannot do error detection.
>>
>>> unsigned long index;
>>> char *endptr;
>>>
>>> index = strtoul(child->name + 9, &endptr, 10);
>>> assert(index >= 0 && !*endptr);
>>
>> Still incorrect; you aren't handling errno properly for detecting all
>> errors. Even better is to use qemu_strtoul(), which already handles
>> proper error detection.
>
> Yeah, I keep forgetting that it returns ULONG_MAX on range error...
Yes, we should limit the range to INT_MAX. How do you like the following
codes, i just steal it from xen_host_pci_get_value().
int rc;
const char *endptr;
unsigned long value;
assert(!strncmp(child->name, "children.", 9));
rc = qemu_strtoul(child->name + 9, &endptr, 10, &value);
if (!rc) {
assert(value <= INT_MAX);
index = value;
} else {
error_setg_errno(errp, -rc, "Failed to parse value '%s'",
child->name + 9);
return;
}
Thanks
-Xie
>
> Max
>
next prev parent reply other threads:[~2016-03-08 2:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 9:37 [Qemu-devel] [PATCH v10 0/3] qapi: child add/delete support Changlong Xie
2016-02-16 9:37 ` [Qemu-devel] [PATCH v10 1/3] Add new block driver interface to add/delete a BDS's child Changlong Xie
2016-03-05 17:27 ` Max Reitz
2016-03-07 4:16 ` Changlong Xie
2016-03-07 15:23 ` Max Reitz
2016-02-16 9:37 ` [Qemu-devel] [PATCH v10 2/3] quorum: implement bdrv_add_child() and bdrv_del_child() Changlong Xie
2016-03-05 18:13 ` Max Reitz
2016-03-07 9:13 ` Changlong Xie
2016-03-07 16:02 ` Eric Blake
2016-03-07 16:02 ` Max Reitz
2016-03-08 2:57 ` Changlong Xie [this message]
2016-03-09 15:27 ` Max Reitz
2016-03-08 1:42 ` Changlong Xie
2016-02-16 9:37 ` [Qemu-devel] [PATCH v10 3/3] qmp: add monitor command to add/remove a child Changlong Xie
2016-03-05 18:33 ` Max Reitz
2016-03-07 9:15 ` Changlong Xie
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=56DE3FAE.6000305@cn.fujitsu.com \
--to=xiecl.fnst@cn.fujitsu.com \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eddie.dong@intel.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=yunhong.jiang@intel.com \
--cc=zhang.zhanghailiang@huawei.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.