[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 04/23] chardev/baum: Avoid dynamic stack allocation
From: |
Samuel Thibault |
Subject: |
Re: [PATCH 04/23] chardev/baum: Avoid dynamic stack allocation |
Date: |
Wed, 5 May 2021 23:15:22 +0200 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Philippe Mathieu-Daudé, le mer. 05 mai 2021 23:10:28 +0200, a ecrit:
> Use autofree heap allocation instead of variable-length
> array on the stack.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> chardev/baum.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/chardev/baum.c b/chardev/baum.c
> index 0822e9ed5f3..bc09cda3471 100644
> --- a/chardev/baum.c
> +++ b/chardev/baum.c
> @@ -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--)
> --
> 2.26.3
>
- [PATCH 00/23] misc: Remove variable-length arrays on the stack, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 01/23] block/vpc: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 03/23] chardev/baum: Use definitions to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 02/23] chardev/baum: Replace magic values by X_MAX / Y_MAX definitions, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 04/23] chardev/baum: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 05/23] io/channel-websock: Replace strlen(const_str) by sizeof(const_str) - 1, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 06/23] hw/block/dataplane/virtio-blk: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
[PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05