From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDj8o-0000jg-JW for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:22:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDj8k-00012H-5K for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:22:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDj8j-000112-MJ for qemu-devel@nongnu.org; Wed, 12 Feb 2014 18:22:50 -0500 Message-ID: <52FC0245.9080603@redhat.com> Date: Wed, 12 Feb 2014 16:22:45 -0700 From: Eric Blake MIME-Version: 1.0 References: <1392186806-10418-1-git-send-email-cyliu@suse.com> <1392186806-10418-4-git-send-email-cyliu@suse.com> In-Reply-To: <1392186806-10418-4-git-send-email-cyliu@suse.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="VutCMP6sOBvv8rV0mI3MbBvCNkf1MFgpo" Subject: Re: [Qemu-devel] [PATCH v20 03/26] improve some functions in qemu-option.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chunyan Liu , qemu-devel@nongnu.org Cc: kwolf@redhat.com, Dong Xu Wang , stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --VutCMP6sOBvv8rV0mI3MbBvCNkf1MFgpo Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 02/11/2014 11:33 PM, Chunyan Liu wrote: > Improve opt_get and opt_set group of functions. For opt_get, check and = handle > NUlL input; for opt_set, when set to an existing option, rewrite the op= tion s/NUlL/NULL/ > with new value. >=20 > Signed-off-by: Dong Xu Wang > Signed-off-by: Chunyan Liu > --- > util/qemu-option.c | 84 +++++++++++++++++++++++++++++++++++++++++++-= ------- > 1 files changed, 70 insertions(+), 14 deletions(-) >=20 > diff --git a/util/qemu-option.c b/util/qemu-option.c > index fd84f95..ea6793a 100644 > --- a/util/qemu-option.c > +++ b/util/qemu-option.c > @@ -499,6 +499,9 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const= char *name) > { > QemuOpt *opt; > =20 > + if (!opts) > + return NULL; > + Why not just 'assert(opts);'? In other words, what caller is planning on passing a NULL opts, since I couldn't find any existing caller that did that? Please update the commit message with justification of how this can simplify a caller in a later patch, if that is your plan; but without that justification, I'm going solely off the diffstat and the fact that no existing caller passes NULL, and concluding that this change is bloat. > + opt =3D qemu_opt_find(opts, name); > if (!opt) { > + > + opt =3D qemu_opt_find(opts, name); > + > if (opt =3D=3D NULL) { Inconsistent styles here; might be worth making them all look alike while touching them, if we keep this patch. > @@ -664,6 +693,13 @@ static void opt_set(QemuOpts *opts, const char *na= me, const char *value, > return; > } > =20 > + opt =3D qemu_opt_find(opts, name); > + if (opt) { > + g_free((char *)opt->str); > + opt->str =3D g_strdup(value); Ugg. Why did the struct declare things as const char *str if we are going to be strdup'ing into it? I worry about attempting to free non-malloc'd memory any time I see a cast to lose a const. Is this just a case of someone incorrectly trying to be const-correct, and now you have to work around it? If you drop the 'const' from option_int.h, do things still compile? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --VutCMP6sOBvv8rV0mI3MbBvCNkf1MFgpo 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJS/AJFAAoJEKeha0olJ0Nq+uoH/3ICFIr4zU/vWe54Vxg78Huh p7yh3iK8nlmnegiEO0+NPwIhpTR5W8Liqn1yhAiP9fu/4wL8b/+LrogQXetWRTDo 2msvJrmgR63ZalZxmjoFSMY1UIRmZL1UKnKX4GalAk9bU4DkKxLL0eycFMkhZLBP V0JLDnSxktdt2dXsnCB+U4F2jAx5L6Rd92vHoI/09EkHSLsm5DW3mH31aNSZTJA7 eUK6ecvULNDBfSMk3+X/hGkVbh8mX0zcXFDqZwMh82nsVhFBny4Zy+QBLjKGp9DG wRWiG8S31pjuxuCbTm+3WrfWwq24XzW4C6MJPBW3VAdWKOIdUii7DNzLs+tUVyk= =B+vN -----END PGP SIGNATURE----- --VutCMP6sOBvv8rV0mI3MbBvCNkf1MFgpo--