From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ad7oo-0000u5-LS for qemu-devel@nongnu.org; Mon, 07 Mar 2016 21:56:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ad7on-0001Kk-RC for qemu-devel@nongnu.org; Mon, 07 Mar 2016 21:56:18 -0500 Message-ID: <56DE3FAE.6000305@cn.fujitsu.com> Date: Tue, 8 Mar 2016 10:57:50 +0800 From: Changlong Xie MIME-Version: 1.0 References: <1455615450-15138-1-git-send-email-xiecl.fnst@cn.fujitsu.com> <1455615450-15138-3-git-send-email-xiecl.fnst@cn.fujitsu.com> <56DB21B7.7050104@redhat.com> <56DDA5FF.2050900@redhat.com> <56DDA630.4000409@redhat.com> In-Reply-To: <56DDA630.4000409@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v10 2/3] quorum: implement bdrv_add_child() and bdrv_del_child() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , Eric Blake , qemu devel , Alberto Garcia , Kevin Wolf , Stefan Hajnoczi Cc: qemu block , Jiang Yunhong , Dong Eddie , Markus Armbruster , "Dr. David Alan Gilbert" , Gonglei , zhanghailiang 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 >