[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 18/23] ui/vnc-enc-hextile: Use definitions to avoid dynamic stack
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 18/23] ui/vnc-enc-hextile: Use definitions to avoid dynamic stack allocation |
Date: |
Wed, 5 May 2021 23:10:42 +0200 |
We know 'pf.bytes_per_pixel' will be at most 'VNC_SERVER_FB_BYTES'
(which is actually 4 bytes for 32bpp). Instead of having the compiler
use variable-length array, use this 'small' maximum length and
autofree to allocate the buffer on the heap.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
ui/vnc-enc-hextile-template.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/ui/vnc-enc-hextile-template.h b/ui/vnc-enc-hextile-template.h
index 0c56262afff..85e67bd9d88 100644
--- a/ui/vnc-enc-hextile-template.h
+++ b/ui/vnc-enc-hextile-template.h
@@ -25,10 +25,11 @@ static void CONCAT(send_hextile_tile_, NAME)(VncState *vs,
int bg_count = 0;
int fg_count = 0;
int flags = 0;
- uint8_t data[(vs->client_pf.bytes_per_pixel + 2) * 16 * 16];
+ g_autofree uint8_t *data = g_malloc((VNC_SERVER_FB_BYTES + 2) * 16 * 16);
int n_data = 0;
int n_subtiles = 0;
+ assert(vs->client_pf.bytes_per_pixel <= VNC_SERVER_FB_BYTES);
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
switch (n_colors) {
--
2.26.3
- [PATCH 13/23] hw/usb/hcd-xhci: Avoid dynamic stack allocation, (continued)
- [PATCH 13/23] hw/usb/hcd-xhci: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 14/23] hw/usb/hcd-ohci: Use definition to avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 15/23] net: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 16/23] ui/curses: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 17/23] ui/spice-display: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 18/23] ui/vnc-enc-hextile: Use definitions to avoid dynamic stack allocation,
Philippe Mathieu-Daudé <=
- [PATCH 19/23] ui/vnc-enc-tight: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 20/23] util/iov: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 22/23] tests/unit/test-vmstate: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 21/23] target/ppc/kvm: Avoid dynamic stack allocation, Philippe Mathieu-Daudé, 2021/05/05
- [PATCH 23/23] configure: Prohibit variable-length allocations by using -Wvla CPPFLAG, Philippe Mathieu-Daudé, 2021/05/05