Skip to contentSkip to conversation

arm: fix malloc type mismatch

PATCH Applied Paolo Bonzini 3 participants 3 messages May 24, 2018 – May 29, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: fix malloc type mismatch

cpregs_keys is an uint32_t* so the allocation should use uint32_t. g_new is even better because it is type-safe.

---
 target/arm/gdbstub.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/gdbstub.c +1 -2
index e80cfb47c7..0c64c0292e 100644
@@ -157,8 +157,7 @@ int arm_gen_dynamic_xml(CPUState *cs)
     RegisterSysregXmlParam param = {cs, s};
 
     cpu->dyn_xml.num_cpregs = 0;
-    cpu->dyn_xml.cpregs_keys = g_malloc(sizeof(uint32_t *) *
-                                        g_hash_table_size(cpu->cp_regs));
+    cpu->dyn_xml.cpregs_keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs));
     g_string_printf(s, "<?xml version=\"1.0\"?>");
     g_string_append_printf(s, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
     g_string_append_printf(s, "<feature name=\"org.qemu.gdb.arm.sys.regs\">");
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw

Cc'ing qemu-devel for patchew and co

Quoted 4 lines · Paolo Bonzini

cpregs_keys is an uint32_t* so the allocation should use uint32_t. g_new is even better because it is type-safe.

Quoted 19 lines
---
 target/arm/gdbstub.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/gdbstub.c +1 -2
index e80cfb47c7..0c64c0292e 100644
@@ -157,8 +157,7 @@ int arm_gen_dynamic_xml(CPUState *cs)
     RegisterSysregXmlParam param = {cs, s};
 
     cpu->dyn_xml.num_cpregs = 0;
-    cpu->dyn_xml.cpregs_keys = g_malloc(sizeof(uint32_t *) *
-                                        g_hash_table_size(cpu->cp_regs));
+    cpu->dyn_xml.cpregs_keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs));
     g_string_printf(s, "<?xml version=\"1.0\"?>");
     g_string_append_printf(s, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
     g_string_append_printf(s, "<feature name=\"org.qemu.gdb.arm.sys.regs\">");