* [Qemu-devel] [PATCH] qxl: Use g_new() & friends where that makes obvious sense
@ 2015-09-14 11:03 Markus Armbruster
2015-09-14 15:26 ` Eric Blake
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2015-09-14 11:03 UTC (permalink / raw)
To: qemu-devel; +Cc: kraxel
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>
---
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 2288238..a05690d 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qxl: Use g_new() & friends where that makes obvious sense
2015-09-14 11:03 [Qemu-devel] [PATCH] qxl: Use g_new() & friends where that makes obvious sense Markus Armbruster
@ 2015-09-14 15:26 ` Eric Blake
0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2015-09-14 15:26 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: kraxel
[-- Attachment #1: Type: text/plain, Size: 736 bytes --]
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.
>
> 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>
> ---
> hw/display/qxl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-14 15:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14 11:03 [Qemu-devel] [PATCH] qxl: Use g_new() & friends where that makes obvious sense Markus Armbruster
2015-09-14 15:26 ` Eric Blake
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).