QEMU-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] disas: converts malloc to g_new0
@ 2026-06-30 22:32 Christian S. Lima
  2026-07-01  5:16 ` Markus Armbruster
  0 siblings, 1 reply; 3+ messages in thread
From: Christian S. Lima @ 2026-06-30 22:32 UTC (permalink / raw)
  To: qemu-devel, Laurent Vivier

Following the qemu coding style change from malloc to g_new0, the
advantages are that g_new0 catch multiplication overflowing size_t,
allows for better detection of type errors because it returns the type
itself and initialize memory with zeros to detect if something go wrong.

Signed-off-by: Christian S. Lima <christianslima@proton.me>
---
Changes in v2:
    - Change from g_malloc0 to g_new0
---
 disas/m68k.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/disas/m68k.c b/disas/m68k.c
index 800b4145ac..c3571783b0 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -1887,8 +1887,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
 
       /* Then create a sorted table of pointers
 	 that point into the unsorted table.  */
-      opc_pointer[0] = malloc (sizeof (struct m68k_opcode *)
-                               * m68k_numopcodes);
+      opc_pointer[0] = g_new0(const struct m68k_opcode *, m68k_numopcodes);
       opcodes[0] = opc_pointer[0];
 
       for (i = 1; i < 16; i++)
-- 
2.53.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-01 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 22:32 [PATCH v2] disas: converts malloc to g_new0 Christian S. Lima
2026-07-01  5:16 ` Markus Armbruster
2026-07-01 10:22   ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox