On Thu, May 6, 2021 at 1:15 AM Philippe Mathieu-Daudé <phi...@redhat.com>
wrote:

> Use autofree heap allocation instead of variable-length
> array on the stack.
>
> Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com>

---
>  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);
>

fwiw, for non-bottleneck code, I would simply use g_malloc0() everywhere,
ymmv

+    uint8_t *cur = io_buf;
>      int room;
>      *cur++ = ESC;
>      while (len--)
> --
> 2.26.3
>
>
>

-- 
Marc-André Lureau

Reply via email to