[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/23] ui/vnc-enc-tight: Avoid dynamic stack allocation
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 19/23] ui/vnc-enc-tight: Avoid dynamic stack allocation |
Date: |
Wed, 5 May 2021 23:10:43 +0200 |
Use autofree heap allocation instead of variable-length
array on the stack.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
ui/vnc-enc-tight.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index cebd35841a9..ff6027cf8d4 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -1097,13 +1097,13 @@ static int send_palette_rect(VncState *vs, int x, int y,
switch (vs->client_pf.bytes_per_pixel) {
case 4:
{
- size_t old_offset, offset;
- uint32_t header[palette_size(palette)];
+ size_t old_offset, offset, palette_sz = palette_size(palette);
+ g_autofree uint32_t *header = g_new(uint32_t, palette_sz);
struct palette_cb_priv priv = { vs, (uint8_t *)header };
old_offset = vs->output.offset;
palette_iter(palette, write_palette, &priv);
- vnc_write(vs, header, sizeof(header));
+ vnc_write(vs, header, palette_sz * sizeof(uint32_t));
if (vs->tight->pixel24) {
tight_pack24(vs, vs->output.buffer + old_offset, colors, &offset);
@@ -1115,11 +1115,12 @@ static int send_palette_rect(VncState *vs, int x, int y,
}
case 2:
{
- uint16_t header[palette_size(palette)];
+ size_t palette_sz = palette_size(palette);
+ g_autofree uint16_t *header = g_new(uint16_t, palette_sz);
struct palette_cb_priv priv = { vs, (uint8_t *)header };
palette_iter(palette, write_palette, &priv);
- vnc_write(vs, header, sizeof(header));
+ vnc_write(vs, header, palette_sz * sizeof(uint16_t));
tight_encode_indexed_rect16(vs->tight->tight.buffer, w * h, palette);
break;
}
--
2.26.3
- [PATCH 14/23] hw/usb/hcd-ohci: Use definition to avoid dynamic stack allocation, (continued)
- [PATCH 14/23] hw/usb/hcd-ohci: Use definition to 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 15/23] net: 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é, 2021/05/05
- [PATCH 19/23] ui/vnc-enc-tight: Avoid dynamic stack allocation,
Philippe Mathieu-Daudé <=
- [PATCH 20/23] util/iov: 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 22/23] tests/unit/test-vmstate: 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