Received: from eggs.gnu.org ([2001:4830:134:3::10]:60155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD8eu-0008GK-L3 for qemu-devel@nongnu.org; Tue, 11 Feb 2014 03:25:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WD8eo-0005b0-B1 for qemu-devel@nongnu.org; Tue, 11 Feb 2014 03:25:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20582) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD8en-0005aM-NI for qemu-devel@nongnu.org; Tue, 11 Feb 2014 03:25:30 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1B8PTFh013069 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Feb 2014 03:25:29 -0500 From: Markus Armbruster References: <1391090848-2115-1-git-send-email-armbru@redhat.com> <20140210155441.5c403529@redhat.com> <20140211012455.GA2923@T430.nay.redhat.com> Date: Tue, 11 Feb 2014 09:25:26 +0100 In-Reply-To: <20140211012455.GA2923@T430.nay.redhat.com> (Fam Zheng's message of "Tue, 11 Feb 2014 09:24:55 +0800") Message-ID: <871tzaukcp.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] Use error_is_set() only when necessary List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org, Luiz Capitulino Fam Zheng writes: > On Mon, 02/10 15:54, Luiz Capitulino wrote: >> > @@ -875,13 +875,13 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) >> > /* Actual block device init: Functionality shared with blockdev-add */ >> > dinfo = blockdev_init(filename, bs_opts, type, &local_err); >> > if (dinfo == NULL) { >> > - if (error_is_set(&local_err)) { >> > + if (local_err) { >> > qerror_report_err(local_err); >> > error_free(local_err); >> > } >> > goto fail; >> > } else { >> > - assert(!error_is_set(&local_err)); >> > + assert(!local_err); >> > } >> >> Not related to this patch, but this else clause is checking if >> dinfo != NULL and local_err != NULL, right? Shouldn't it be moved >> into blockdev_init() instead? > > This is just an caller checking that the output of blockdev_init is sane, so I > think it's OK to put an assertion here. Yes, this is a common problem with functions returning a non-null pointer on success, null pointer and an error object on failure. Which of the two should the caller test to figure out success vs. failure? If it only tests the return value, and a buggy callee returns an error object along with a null return value, the error object is leaked. If it only tests for an error object, and a buggy callee returns a null pointer along with an error object, we'll almost certainly crash some time later dereferencing the null return value. If it tests both, it'll have to deal with inconsistencies. This is what this caller does.