Skip to contentSkip to conversation

linux-user: replace calloc() with g_new0()

PATCH Applied Nguyen Dinh Phi 3 participants 3 messages Mar 17, 2024 – Apr 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: replace calloc() with g_new0()

Use glib allocation as recommended by the coding convention

---
 linux-user/main.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
linux-user/main.c +1 -5
index 9277df2e9d..149e35432e 100644
@@ -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
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Nguyen Dinh Phi

Use glib allocation as recommended by the coding convention

---
 linux-user/main.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
linux-user/main.c +0 -0
index 9277df2e9d..149e35432e 100644

linux-user/main.c int main(int argc, char **argv, char **envp) · line 931

Quoted 9 lines
linux-user/main.c +1 -5
@@ -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);
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#2 lore raw
In reply to Nguyen Dinh Phi
Quoted 14 lines · Nguyen Dinh Phi

Use glib allocation as recommended by the coding convention

---
  linux-user/main.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
linux-user/main.c +0 -0
index 9277df2e9d..149e35432e 100644
@@ -928,11 +928,7 @@ int main(int argc, char **argv, char **envp)
       * Prepare copy of argv vector for target.
       */

linux-user/main.c int main(int argc, char **argv, char **envp) · line 934

Quoted 10 lines
linux-user/main.c +1 -5
      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~