diff mbox series

[28/88] disas: use g_new() family of functions

Message ID 20171006235023.11952-29-f4bug@amsat.org
State New
Headers show
Series use g_new() family of functions | expand

Commit Message

Philippe Mathieu-Daudé Oct. 6, 2017, 11:49 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
[PMD: fixed const cast, squashed M68K + NiosII + SPARC, renamed subject "disas"]
---
 disas/m68k.c  | 3 +--
 disas/nios2.c | 3 +--
 disas/sparc.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/disas/m68k.c b/disas/m68k.c
index 61b689ef3e..31cf6ea5f9 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -1886,8 +1886,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_new(const struct m68k_opcode *, m68k_numopcodes);
       opcodes[0] = opc_pointer[0];
 
       for (i = 1; i < 16; i++)
diff --git a/disas/nios2.c b/disas/nios2.c
index b342936d21..9e6e1e6a1f 100644
--- a/disas/nios2.c
+++ b/disas/nios2.c
@@ -2625,8 +2625,7 @@  nios2_init_opcode_hash (nios2_disassembler_state *state)
 
 	if (bucket)
 	  {
-	    new_hash =
-	      (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
+	    new_hash = g_new(nios2_opcode_hash, 1);
 	    if (new_hash == NULL)
 	      {
 		fprintf (stderr,
diff --git a/disas/sparc.c b/disas/sparc.c
index f120f4e86d..6d0adab8a7 100644
--- a/disas/sparc.c
+++ b/disas/sparc.c
@@ -2684,8 +2684,7 @@  print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
       current_arch_mask = compute_arch_mask (info->mach);
 
       if (!opcodes_initialized)
-        sorted_opcodes =
-          malloc (sparc_num_opcodes * sizeof (sparc_opcode *));
+        sorted_opcodes = g_new(const sparc_opcode *, sparc_num_opcodes);
       /* Reset the sorted table so we can resort it.  */
       for (i = 0; i < sparc_num_opcodes; ++i)
         sorted_opcodes[i] = &sparc_opcodes[i];