qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH v2 3/4] qxl: Use g_new() & friends where that makes obvious sense
Date: Thu, 29 Oct 2015 16:55:21 +0100	[thread overview]
Message-ID: <1446134122-32292-4-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1446134122-32292-1-git-send-email-armbru@redhat.com>

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.

This commit only touches allocations with size arguments of the form
sizeof(T).  Same Coccinelle semantic patch as in commit b45c03f.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 hw/display/qxl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 9c961da..8a3040c 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -2156,7 +2156,7 @@ static int qxl_post_load(void *opaque, int version)
         qxl_create_guest_primary(d, 1, QXL_SYNC);
 
         /* replay surface-create and cursor-set commands */
-        cmds = g_malloc0(sizeof(QXLCommandExt) * (d->ssd.num_surfaces + 1));
+        cmds = g_new0(QXLCommandExt, d->ssd.num_surfaces + 1);
         for (in = 0, out = 0; in < d->ssd.num_surfaces; in++) {
             if (d->guest_surfaces.cmds[in] == 0) {
                 continue;
-- 
2.4.3

  parent reply	other threads:[~2015-10-29 15:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
2015-11-03 12:06   ` Michael Tokarev
2015-11-03 13:49     ` Markus Armbruster
2015-11-03 16:12   ` [Qemu-devel] [PATCH v3 " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 2/4] audio: " Markus Armbruster
2015-10-29 15:55 ` Markus Armbruster [this message]
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 4/4] usb: " Markus Armbruster
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
2015-10-30 11:31   ` Gerd Hoffmann
2015-10-30 14:16   ` Markus Armbruster
2015-11-03 12:09 ` Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446134122-32292-4-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).