From dca5da02a04571d0baa28712846539b7588d7d8f Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 20 Oct 2021 13:34:16 +1100 Subject: [PATCH] [client] egl: fix undefined behaviour with zero size array --- client/renderers/EGL/desktop_rects.c | 6 ++++++ common/src/rects.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/client/renderers/EGL/desktop_rects.c b/client/renderers/EGL/desktop_rects.c index 5c0edf51..8d97e5ce 100644 --- a/client/renderers/EGL/desktop_rects.c +++ b/client/renderers/EGL/desktop_rects.c @@ -107,6 +107,12 @@ inline static void rectToVertices(GLfloat * vertex, const FrameDamageRect * rect void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * data, int width, int height) { + if (data && data->count == 0) + { + rects->count = 0; + return; + } + GLfloat vertices[(!data || data->count < 0 ? 1 : data->count) * 8]; if (!data || data->count < 0) { diff --git a/common/src/rects.c b/common/src/rects.c index c6b93699..80257ee6 100644 --- a/common/src/rects.c +++ b/common/src/rects.c @@ -211,6 +211,9 @@ inline static bool rectIntersects(const FrameDamageRect * r1, const FrameDamageR int rectsMergeOverlapping(FrameDamageRect * rects, int count) { + if (count == 0) + return 0; + bool removed[count]; bool changed;