OSDN Git Service

chardev/baum: Avoid dynamic stack allocation
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Fri, 19 Aug 2022 15:39:23 +0000 (16:39 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 22 Sep 2022 15:38:28 +0000 (16:38 +0100)
Use autofree heap allocation instead of variable-length
array on the stack.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20220819153931.3147384-4-peter.maydell@linaro.org

chardev/baum.c

index 6a210ff..0a0d126 100644 (file)
@@ -299,7 +299,8 @@ static void baum_chr_accept_input(struct Chardev *chr)
 static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
 {
     Chardev *chr = CHARDEV(baum);
-    uint8_t io_buf[1 + 2 * len], *cur = io_buf;
+    g_autofree uint8_t *io_buf = g_malloc(1 + 2 * len);
+    uint8_t *cur = io_buf;
     int room;
     *cur++ = ESC;
     while (len--)