From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbVhq-0007JZ-9X for qemu-devel@nongnu.org; Mon, 14 Sep 2015 11:30:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbVhm-0004Tk-47 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 11:30:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbVhl-0004Su-U0 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 11:30:06 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id A8E41A0B60 for ; Mon, 14 Sep 2015 15:30:05 +0000 (UTC) References: <1442228637-31481-3-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55F6E7F9.5010602@redhat.com> Date: Mon, 14 Sep 2015 09:30:01 -0600 MIME-Version: 1.0 In-Reply-To: <1442228637-31481-3-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0tCqrkjh5RotrhUXgGGiH7KRiLbtUKh7r" Subject: Re: [Qemu-devel] [PATCH] ui: Use g_new() & friends where that makes obvious sense List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kraxel@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --0tCqrkjh5RotrhUXgGGiH7KRiLbtUKh7r Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/14/2015 05:03 AM, Markus Armbruster wrote: > g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, > for two reasons. One, it catches multiplication overflowing size_t. > Two, it returns T * rather than void *, which lets the compiler catch > more type errors. >=20 > This commit only touches allocations with size arguments of the form > sizeof(T). Same Coccinelle semantic patch as in commit b45c03f. >=20 > Signed-off-by: Markus Armbruster > --- > ui/console.c | 2 +- > ui/curses.c | 2 +- > ui/input-legacy.c | 4 ++-- > ui/keymaps.c | 2 +- > ui/sdl.c | 2 +- > ui/vnc-jobs.c | 6 +++--- > ui/vnc.c | 6 +++--- > 7 files changed, 12 insertions(+), 12 deletions(-) Reviewed-by: Eric Blake >=20 > diff --git a/ui/console.c b/ui/console.c > index 75fc492..6edda1e 100644 > --- a/ui/console.c > +++ b/ui/console.c > @@ -449,7 +449,7 @@ static void text_console_resize(QemuConsole *s) > if (s->width < w1) > w1 =3D s->width; > =20 > - cells =3D g_malloc(s->width * s->total_height * sizeof(TextCell));= > + cells =3D g_new(TextCell, s->width * s->total_height); Hopefully s->width * s->total_height can't overflow. > @@ -3025,7 +3025,7 @@ static void vnc_connect(VncDisplay *vd, int csock= , > =20 > vs->lossy_rect =3D g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_re= ct)); > for (i =3D 0; i < VNC_STAT_ROWS; ++i) { > - vs->lossy_rect[i] =3D g_malloc0(VNC_STAT_COLS * sizeof (uint8_= t)); > + vs->lossy_rect[i] =3D g_new0(uint8_t, VNC_STAT_COLS); sizeof(uint8_t) =3D=3D 1, according to POSIX. This could be further simplified to g_malloc0(VNC_STAT_COLS). But if someone wants to do that simplification, it should be a separate patch. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --0tCqrkjh5RotrhUXgGGiH7KRiLbtUKh7r Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJV9uf5AAoJEKeha0olJ0NqDdQH+wfXarHj7uWLz4BJGZb1P/WL Q3H9bhxN8Xx5q6CWwSU0+GRruPQMRoyAfM6CytxLtMzK/PAv4aa9hattMvkPQjFu nw8/J5iIvw+orIPWGfqdXFcnMbqCzadyFgOXvHtLl5UuAbPcahHfokmIf7TBhJe0 b6SJ69cAqs2gtGTyxqbWcjUJCarJQlyuXCIQfcMreH5ZEa5D31j0pA/g5WXd6fQx 0InbDWNgj7D1dBeE8foEB6CRTk9ZeSniquNkXlWEHRIJDF1CRJl9le9mraIS+9L5 uWk0pUaDA3gJqckxXX0C+q2fEfO/HTmaznuUVWNSVpy/QU+74SCQ06IqApwJJHE= =GjuJ -----END PGP SIGNATURE----- --0tCqrkjh5RotrhUXgGGiH7KRiLbtUKh7r--