[PATCH] linux-user: replace calloc() with g_new0()

Nguyen Dinh Phi posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240317171747.1642207-1-phind.uet@gmail.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/main.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
[PATCH] linux-user: replace calloc() with g_new0()
Posted by Nguyen Dinh Phi 1 month, 1 week ago
Use glib allocation as recommended by the coding convention

Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
---
 linux-user/main.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9277df2e9d..149e35432e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -928,11 +928,7 @@ int main(int argc, char **argv, char **envp)
      * Prepare copy of argv vector for target.
      */
     target_argc = argc - optind;
-    target_argv = calloc(target_argc + 1, sizeof (char *));
-    if (target_argv == NULL) {
-        (void) fprintf(stderr, "Unable to allocate memory for target_argv\n");
-        exit(EXIT_FAILURE);
-    }
+    target_argv = g_new0(char *, target_argc + 1);
 
     /*
      * If argv0 is specified (using '-0' switch) we replace
-- 
2.34.1
Re: [PATCH] linux-user: replace calloc() with g_new0()
Posted by Richard Henderson 3 weeks ago
On 3/17/24 07:17, Nguyen Dinh Phi wrote:
> Use glib allocation as recommended by the coding convention
> 
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> ---
>   linux-user/main.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 9277df2e9d..149e35432e 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -928,11 +928,7 @@ int main(int argc, char **argv, char **envp)
>        * Prepare copy of argv vector for target.
>        */
>       target_argc = argc - optind;
> -    target_argv = calloc(target_argc + 1, sizeof (char *));
> -    if (target_argv == NULL) {
> -        (void) fprintf(stderr, "Unable to allocate memory for target_argv\n");
> -        exit(EXIT_FAILURE);
> -    }
> +    target_argv = g_new0(char *, target_argc + 1);
>   
>       /*
>        * If argv0 is specified (using '-0' switch) we replace

Queued, thanks.


r~
Re: [PATCH] linux-user: replace calloc() with g_new0()
Posted by Alex Bennée 1 month, 1 week ago
Nguyen Dinh Phi <phind.uet@gmail.com> writes:

> Use glib allocation as recommended by the coding convention
>
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> ---
>  linux-user/main.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 9277df2e9d..149e35432e 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -928,11 +928,7 @@ int main(int argc, char **argv, char **envp)
>       * Prepare copy of argv vector for target.
>       */
>      target_argc = argc - optind;
> -    target_argv = calloc(target_argc + 1, sizeof (char *));
> -    if (target_argv == NULL) {
> -        (void) fprintf(stderr, "Unable to allocate memory for target_argv\n");
> -        exit(EXIT_FAILURE);
> -    }
> +    target_argv = g_new0(char *, target_argc + 1);

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro