Received: from eggs.gnu.org ([2001:4830:134:3::10]:59003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRzcc-0004qC-EL for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRzcU-0005Cb-8J for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:20:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRzcT-0005CX-V7 for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:20:46 -0400 From: Markus Armbruster References: <1410336832-22160-1-git-send-email-armbru@redhat.com> <1410336832-22160-2-git-send-email-armbru@redhat.com> <20140910110339.GA10817@irqsave.net> <541068B2.3040103@redhat.com> Date: Thu, 11 Sep 2014 10:20:40 +0200 In-Reply-To: <541068B2.3040103@redhat.com> (Eric Blake's message of "Wed, 10 Sep 2014 09:05:22 -0600") Message-ID: <87wq9atvon.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 01/23] block: Split bdrv_new_named() off bdrv_new() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: =?utf-8?Q?Beno=C3=AEt?= Canet , kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Eric Blake writes: > On 09/10/2014 05:03 AM, Beno=C3=AEt Canet wrote: >> The Wednesday 10 Sep 2014 =C3=A0 10:13:30 (+0200), Markus Armbruster wro= te : >>> Creating an anonymous BDS can't fail. Make that obvious. >>> >>> Signed-off-by: Markus Armbruster >>> --- > >>> /* create a new block device (by default it is empty) */ >>> -BlockDriverState *bdrv_new(const char *device_name, Error **errp) >>> +BlockDriverState *bdrv_new_named(const char *device_name, Error **errp) >>> { >>> BlockDriverState *bs; >>> - int i; >>> + >>> + assert(*device_name); >>=20 >> This assert that device_name is not a null pointer. > > No, it assumes that device_name is non-NULL and blindly dereferences it; > it is asserting that the first byte of the dereferenced pointer is not NU= L. > >> But here we are pretty sure that the BDS should be named given the >> name of the function. >> Should we bake an assert on device_name[0] !=3D '\0' to avoid >> bdrv_new_named being called >> with "" as device_name ? > > That's already what the code does. About the only thing it could do > differently is: > > assert(device_name && *device_name); Converts a crash into an assertion failure. No difference to me, but if you guys think it's a worthwhile improvement...