From e85f219affb94ea0ef8ef3c4805041376986982a Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 29 Mar 2020 13:09:28 +0000 Subject: [PATCH] Make sure damage buffer is properly aligned --- src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index d22ba22..9669b03 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "wlr-export-dmabuf-unstable-v1.h" #include "wlr-screencopy-unstable-v1.h" @@ -54,6 +55,9 @@ #define DEFAULT_ADDRESS "127.0.0.1" #define DEFAULT_PORT 5900 +#define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) +#define ALIGN_UP(n, a) (UDIV_UP(n, a) * a) + enum frame_capture_backend_type { FRAME_CAPTURE_BACKEND_NONE = 0, FRAME_CAPTURE_BACKEND_SCREENCOPY, @@ -540,7 +544,10 @@ void wayvnc_process_frame(struct wayvnc* self) .x2 = tfx1, .y2 = tfy1, }; - uint8_t* damage_buffer = malloc(width * height); + size_t alignment = MAX(4, sizeof(void*)); + size_t damage_buffer_size = ALIGN_UP(width * height, alignment); + uint8_t* damage_buffer = + aligned_alloc(alignment, damage_buffer_size); render_damage(&self->renderer); renderer_read_damage(&self->renderer, damage_buffer, 0, height);