diff mbox series

[4/5] gdbstub: Replace alloca() by g_new()

Message ID 20210505170055.1415360-5-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Replace alloca() by g_malloc() | expand

Commit Message

Philippe Mathieu-Daudé May 5, 2021, 5 p.m. UTC
The ALLOCA(3) man-page mentions its "use is discouraged".

Replace it by a g_new() call.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 gdbstub.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index 0d5569ee539..72b4be89c7b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1475,7 +1475,9 @@  static int process_string_cmd(void *user_ctx, const char *data,
                               const GdbCmdParseEntry *cmds, int num_cmds)
 {
     int i, schema_len, max_num_params = 0;
-    GdbCmdContext gdb_ctx;
+    g_autofree GdbCmdVariant *params = g_new(GdbCmdVariant,
+                                        GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE / 2);
+    GdbCmdContext gdb_ctx = { .params = params };
 
     if (!cmds) {
         return -1;
@@ -1499,8 +1501,6 @@  static int process_string_cmd(void *user_ctx, const char *data,
             max_num_params = schema_len / 2;
         }
 
-        gdb_ctx.params =
-            (GdbCmdVariant *)alloca(sizeof(*gdb_ctx.params) * max_num_params);
         memset(gdb_ctx.params, 0, sizeof(*gdb_ctx.params) * max_num_params);
 
         if (cmd_parse_params(&data[strlen(cmd->cmd)], cmd->schema,