From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKbO6-0001eN-Hf for qemu-devel@nongnu.org; Tue, 26 Mar 2013 17:26:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKbO4-0005Bi-B7 for qemu-devel@nongnu.org; Tue, 26 Mar 2013 17:26:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKbO4-0005Bd-3e for qemu-devel@nongnu.org; Tue, 26 Mar 2013 17:26:32 -0400 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 r2QLQVZY025675 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Mar 2013 17:26:31 -0400 Message-ID: <51521285.30406@redhat.com> Date: Tue, 26 Mar 2013 15:26:29 -0600 From: Eric Blake MIME-Version: 1.0 References: <30db14a4083032599fe732b07ff5cde2dc190c67.1363957855.git.phrdina@redhat.com> In-Reply-To: <30db14a4083032599fe732b07ff5cde2dc190c67.1363957855.git.phrdina@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2NNPRGXKNTUISBHXTKHHL" Subject: Re: [Qemu-devel] [PATCH v2 08/12] qemu-img: introduce qemu_img_handle_error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pavel Hrdina Cc: lcapitulino@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2NNPRGXKNTUISBHXTKHHL Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/22/2013 07:16 AM, Pavel Hrdina wrote: > Signed-off-by: Pavel Hrdina > --- > qemu-img.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) >=20 > diff --git a/qemu-img.c b/qemu-img.c > index 21d02bf..34badad 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -322,6 +322,14 @@ static int add_old_style_options(const char *fmt, = QEMUOptionParameter *list, > return 0; > } > =20 > +static void qemu_img_handle_error(Error *err) > +{ > + if (error_is_set(&err)) { Here you say it is permissible to pass in an unset err,... > + error_report("%s", error_get_pretty(err)); > + error_free(err); > + } > +} > + > static int img_create(int argc, char **argv) > { > int c; > @@ -401,8 +409,7 @@ static int img_create(int argc, char **argv) > bdrv_img_create(filename, fmt, base_filename, base_fmt, > options, img_size, BDRV_O_FLAGS, &local_err, quiet= ); > if (error_is_set(&local_err)) { > - error_report("%s", error_get_pretty(local_err)); > - error_free(local_err); > + qemu_img_handle_error(local_err); =2E..which means you are duplicating the error_is_set() call here. > return 1; > } Does it make sense to have qemu_img_handle_error() return a different value according to whether an error was present, so that you could instead write: if (qemu_img_handle_error(local_err) < 0) { return 1; } Or, if all callers are already checking for an actual error before calling qemu_img_handle_error (for other reasons, such as img_create's reason of control flow), should you drop the redundant condition out of the helper function? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2NNPRGXKNTUISBHXTKHHL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRUhKFAAoJEKeha0olJ0NqpRQIAI5AIsr0Erlk4tbIzBI4RiZZ uiIV7nIpa79RVx0EXrPw/KW8RlT4slbIOsMPoworcJOk3T/faVdULSz1dnFlpz53 NARxCmczM1VvFerl9Qkf7Y0CEphJJzzY9dsVOZ5JXrkpsNjjTiyG9oe2i8xhxESo smXPySHltM5HiK70oOwapT4xN1amN0cFi8icAvFvZkPkrbYzfaHX+0/kvrmrHnrc bBLRacOKpznyorMJiYfuq1cVg2qYfF5KsnHAbEm+dMsYE0WZeiY4iwoDX7BuXP8B 0NoR5jg2JUMJtkax3yzZ5FsYNhS1xc5DcPEefxJVJpDgqUJEaK4RWW1NM2yV128= =mhGO -----END PGP SIGNATURE----- ------enig2NNPRGXKNTUISBHXTKHHL--