sparc: Use g_memdup() instead of g_new0() + memcpy()
PATCH 1/1 sparc: Use g_memdup() instead of g_new0() + memcpy()
There is no need to make sure that the memory is zeroed after the allocation if we also immediatly fill the whole buffer afterwards with memcpy(). Thus g_new0 should be g_new instead. But since we are also doing a memcpy() here, we can also simply replace both with g_memdup() instead.
--- target-sparc/cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target-sparc/cpu.c +1 -2
@@ -115,8 +115,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const char *cpu_model)return -1 ; } - env->def =g_new0 (sparc_def_t,1 ); -memcpy (env->def, def,sizeof (*def)); + env->def =g_memdup (def,sizeof (*def)); featurestr =strtok (NULL ,"," ); cc->parse_features (CPU (cpu), featurestr, &err);
Signature · 1 line
1.8.3.1
Quoted 28 lines · Thomas Huth
There is no need to make sure that the memory is zeroed after the allocation if we also immediatly fill the whole buffer afterwards with
memcpy(). Thusg_new0should beg_newinstead. But since we are also doing amemcpy()here, we can also simply replace both withg_memdup()instead.Signed-off-by Thomas Huth <[email protected]>--- target-sparc/cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)target-sparc/cpu.c +1
-3@@ -115,8 +115,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const char *cpu_model)return -1 ; } - env->def =g_new0 (sparc_def_t,1 ); -memcpy (env->def, def,sizeof (*def)); + env->def =g_memdup (def,sizeof (*def)); featurestr =strtok (NULL ,"," ); cc->parse_features (CPU (cpu), featurestr, &err); --1.8.3.1
Signature · 4 lines
Regards, Artyom Tarasenko SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu
Michael Tokarev
AppliedQuoted 5 lines · Thomas Huth
There is no need to make sure that the memory is zeroed after the allocation if we also immediatly fill the whole buffer afterwards with
memcpy(). Thusg_new0should beg_newinstead. But since we are also doing amemcpy()here, we can also simply replace both withg_memdup()instead.
Applied to -trivial, thanks!
/mjt