linux-user: Use g_new() & friends where that makes obvious sense
PATCH 1/1 linux-user: Use g_new() & friends where that makes obvious sense
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). Same Coccinelle semantic patchas in commit b45c03f.
--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
linux-user/elfload.c +1 -1
@@ -2848,7 +2848,7 @@ static int fill_note_info(struct elf_note_info *info,TaskState *ts = (TaskState *)cpu->opaque;int i; - info->notes =g_malloc0 (NUMNOTES *sizeof (struct memelfnote )); + info->notes = g_new0(struct memelfnote, NUMNOTES);if (info->notes ==NULL )return (-ENOMEM ); info->prstatus =g_malloc0 (sizeof (*info->prstatus));
linux-user/main.c +1 -1
@@ -4014,7 +4014,7 @@ int main(int argc, char **argv, char **envp) } target_argv[target_argc] =NULL ; - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* build Task State */ ts->info = info;
linux-user/syscall.c +1 -1
@@ -4560,7 +4560,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,new_thread_info info;pthread_attr_t attr; - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* we create a new CPU instance. */ new_env =cpu_copy (env);
Signature · 1 line
2.4.3
Quoted 8 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_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). Same Coccinelle semantic patchas in commit b45c03f.
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 8 lines · Eric Blake
Quoted 7 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_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). Same Coccinelle semantic patchas in commit b45c03f.
s/patchas/patch as/
Quoted 10 lines
Quoted 7 lines
Signed-off-by Markus Armbruster <[email protected]>--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)Reviewed-by Eric Blake <[email protected]>
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Ping?
Quoted 54 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_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). Same Coccinelle semantic patchas in commit b45c03f.
Signed-off-by Markus Armbruster <[email protected]>--- linux-user/elfload.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)linux-user/elfload.c +1
-1@@ -2848,7 +2848,7 @@ static int fill_note_info(struct elf_note_info *info,TaskState *ts = (TaskState *)cpu->opaque;int i; - info->notes =g_malloc0 (NUMNOTES *sizeof (struct memelfnote )); + info->notes = g_new0(struct memelfnote, NUMNOTES);if (info->notes ==NULL )return (-ENOMEM ); info->prstatus =g_malloc0 (sizeof (*info->prstatus));linux-user/main.c +1
-1@@ -4014,7 +4014,7 @@ int main(int argc, char **argv, char **envp) } target_argv[target_argc] =NULL ; - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* build Task State */ ts->info = info;linux-user/syscall.c +1
-1@@ -4560,7 +4560,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,new_thread_info info;pthread_attr_t attr; - ts =g_malloc0 (sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts);/* we create a new CPU instance. */ new_env =cpu_copy (env);
Stefan Weil
Reviewed-by-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Am 24.09.2015 um 09:06 schrieb Markus Armbruster:
Quoted 17 lines
Ping?
Quoted 13 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_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). Same Coccinelle semantic patchas in commit b45c03f.
Signed-off-by Markus Armbruster <[email protected]> ---
linux-user/elfload.c| 2 +-linux-user/main.c| 2 +-linux-user/syscall.c| 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
This patch is trivial enough for qemu-trivial.
As Eric has written, the commit message needs
a small correction: s/patchas/patch as/
Regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBCAAGBQJWA6OuAAoJEOCMIdVndFCt6Q8P/R6kKihtOvr17lL3Av117n1z YPv6Tfa9jy1fd3qaeIMhXgm63CNTWTGU4o0A9/k3thqiD9kYVpqeZkd7gt1gE6uU QR/eReEMZNr+5AnkYnCmZ8wr5upd4RWUjCvbGSUpFgb1ui+VtwZ08XzCVehQfY39 2S6EWxR/I7ETxzue+AFZak9w4QqVF7IQmw7CPkeTCD/himdCpyeGxL9dYQnyfEdW mQeXUR2eipaqwIt1b6JkwQCU78rY2D/OLVDipZK9M4BSmJQWS2BsLboc+VC59bN9 JkVrKgSbuciqBMXDudY71qv9XO/wyM8MwnDM5GY7V9N1PoRVcg2mvSCRKq9lP82K V0Sb6n1j9/AgM3ngnLZqkiVYkeFrnccIkiKCJvmDnDP1ClC8Cy5V1wkPzk7TJgTK 4xvuI3kfWPIzbphWzZtcCstJKYaO5ydrEGGNGko37A6s65oE+gIhyrv/KSIhix+H n7KMOILY4wuk7UYoIgK6cvKL6QsVyhw0lR+RIR8p33ofAj20HylQng38h6spr50F XTl3J38ApbyxNhw+EJHXXwj14YJFrZTwN8C0X49UHkSD4wqR4lH+2kdNUYIYJJHR Zx+HkJj/8hLQq14WjtgZlNQ7noAck/yh9Rvyu54v6yfx1RAhNkDbiysQKgqkWzNM U5ro2khoY2BrI7Bdq29H
=/Z+4
-----END PGP SIGNATURE-----
Quoted 14 lines · Stefan Weil
Am 24.09.2015 um 09:06 schrieb Markus Armbruster:
Quoted 13 lines
Ping?
Quoted 9 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_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). Same Coccinelle semantic patchas in commit b45c03f.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Signed-off-by Markus Armbruster <[email protected]> ---
linux-user/elfload.c| 2 +-linux-user/main.c| 2 +-linux-user/syscall.c| 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)Reviewed-by Stefan Weil <[email protected]>This patch is trivial enough for qemu-trivial.
I guess it is. For code with a maintainer, I tend to try the maintainer first.
Quoted 2 lines
As Eric has written, the commit message needs
a small correction: s/patchas/patch as/
Yes.
Michael Tokarev
AppliedQuoted 9 lines · Stefan Weil
Am 24.09.2015 um 09:06 schrieb Markus Armbruster:
Quoted 8 lines
Ping?
Quoted 4 lines · Markus Armbruster
g_new(T, n)is neater thang_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowingsize_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors.
Applied to -trivial, with a trivial commit message fix. Thanks!
/mjt