From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkEf-0001X3-6S for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:17:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMkEe-0006EU-4H for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:17:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkEd-0006EJ-RX for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:17:40 -0400 Message-ID: <5159DD48.3030806@redhat.com> Date: Mon, 01 Apr 2013 13:17:28 -0600 From: Eric Blake MIME-Version: 1.0 References: <1363961953-13561-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363961953-13561-16-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1363961953-13561-16-git-send-email-xiawenc@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2EOHEDRTCSDIAKTGACKLL" Subject: Re: [Qemu-devel] [PATCH V10 15/17] block: dump to buffer for bdrv_image_info_dump() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, qemu-devel@nongnu.org, armbru@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2EOHEDRTCSDIAKTGACKLL Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/22/2013 08:19 AM, Wenchao Xia wrote: > This allow hmp use this function, just like qemu-img. > It also returns a pointer now to make it easy to use. >=20 > =20 > -void bdrv_image_info_dump(ImageInfo *info) > +GCC_FMT_ATTR(3, 4) > +static void snprintf_tail(char **p_buf, int *p_size, const char *fmt, = =2E..) Yuck. I'm too worried that you are likely to cause truncation when you exceed the bounds of the fixed-width buffer. And you can't argue that this is here to avoid malloc pressure, since... > =20 > +#define IMAGE_INFO_BUF_SIZE (2048) > static void dump_human_image_info_list(ImageInfoList *list) > { > ImageInfoList *elem; > bool delim =3D false; > + char *buf =3D g_malloc0(IMAGE_INFO_BUF_SIZE); =2E..you are doing a malloc for the original buffer in the first place. I'd much rather see use of g_string_append_printf or some similar glib interface that manages a dynamically-sized output buffer to begin with, than to attempt to force the output to fit in a fixed-width malloc'd buff= er. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2EOHEDRTCSDIAKTGACKLL 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/ iQEcBAEBCAAGBQJRWd1IAAoJEKeha0olJ0NqYH8H/2JD0GbTKIbnY2ZMfPU7/0a6 XgUm7acXfOfcVsLTyf4mqHH3WxblZts+FtEmrk1hZaCySHYm9OHtQ9M4zrlFkrbY 2fyqD9+d9kT0LHhyq/KeEuB3HkGMLqCJMYSd0QntAk5BIgOHqAl+l5wFUv/YyAlH iS2dRtTBcqYYbD9rPL6mBFkDnaVZvQLns8K4p/0lSSoHK18afYThruX5rpIvjbc6 7LK7ynCn//qOlNLa0pQFqC4kR7nYB+y+y34MdhaIAMYL/lgQrYWneRO5YZ28J+8q zAA43Fr5p34FhUI+th+0KbtTw043E7x90f6GiVqB0GA0FxWzGL3NyVNzT5ZKWyI= =NCFI -----END PGP SIGNATURE----- ------enig2EOHEDRTCSDIAKTGACKLL--