[PATCH 16/23] ui/curses: Avoid dynamic stack allocation

Philippe Mathieu-Daudé posted 23 patches 4 years, 7 months ago
There is a newer version of this series
[PATCH 16/23] ui/curses: Avoid dynamic stack allocation
Posted by Philippe Mathieu-Daudé 4 years, 7 months ago
Use autofree heap allocation instead of variable-length
array on the stack.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 ui/curses.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/curses.c b/ui/curses.c
index e4f9588c3e8..f490b2d839d 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -65,7 +65,7 @@ static void curses_update(DisplayChangeListener *dcl,
                           int x, int y, int w, int h)
 {
     console_ch_t *line;
-    cchar_t curses_line[width];
+    g_autofree cchar_t *curses_line = g_new(cchar_t, width);
     wchar_t wch[CCHARW_MAX];
     attr_t attrs;
     short colors;
-- 
2.26.3

Re: [PATCH 16/23] ui/curses: Avoid dynamic stack allocation
Posted by Richard Henderson 4 years, 7 months ago
On 5/5/21 2:10 PM, Philippe Mathieu-Daudé wrote:
> Use autofree heap allocation instead of variable-length
> array on the stack.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@redhat.com>
> ---
>   ui/curses.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~