mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
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).
Coccinelle semantic patch:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_try_malloc(sizeof(T))
+g_try_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
@@
-g_try_malloc0(sizeof(T))
+g_try_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_try_malloc(sizeof(T) * (n))
+g_try_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression n;
@@
-g_try_malloc0(sizeof(T) * (n))
+g_try_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression p, n;
@@
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
@@
type T;
expression n;
@@
-(T *)g_new(T, n)
+g_new(T, n)
@@
type T;
expression n;
@@
-(T *)g_new0(T, n)
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
|
||
|---|---|---|
| .. | ||
| ads7846.c | ||
| blizzard.c | ||
| blizzard_template.h | ||
| cg3.c | ||
| cirrus_vga.c | ||
| cirrus_vga_rop.h | ||
| cirrus_vga_rop2.h | ||
| exynos4210_fimd.c | ||
| framebuffer.c | ||
| framebuffer.h | ||
| g364fb.c | ||
| jazz_led.c | ||
| Makefile.objs | ||
| milkymist-tmu2.c | ||
| milkymist-vgafb.c | ||
| milkymist-vgafb_template.h | ||
| omap_dss.c | ||
| omap_lcd_template.h | ||
| omap_lcdc.c | ||
| pl110.c | ||
| pl110_template.h | ||
| pxa2xx_lcd.c | ||
| pxa2xx_template.h | ||
| qxl-logger.c | ||
| qxl-render.c | ||
| qxl.c | ||
| qxl.h | ||
| sm501.c | ||
| sm501_template.h | ||
| ssd0303.c | ||
| ssd0323.c | ||
| tc6393xb.c | ||
| tc6393xb_template.h | ||
| tcx.c | ||
| vga-helpers.h | ||
| vga-isa-mm.c | ||
| vga-isa.c | ||
| vga-pci.c | ||
| vga.c | ||
| vga.h | ||
| vga_int.h | ||
| virtio-gpu-pci.c | ||
| virtio-gpu.c | ||
| virtio-vga.c | ||
| vmware_vga.c | ||
| xenfb.c | ||