From 1b2ea883b0ba9788de5e7362f8b95c496f5eb272 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 3 Nov 2026 13:40:27 +0530 Subject: [PATCH] Make CodeQL happy --- glfw/wl_client_side_decorations.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/glfw/wl_client_side_decorations.c b/glfw/wl_client_side_decorations.c index a48d193a9..3b5aae2ea 100644 --- a/glfw/wl_client_side_decorations.c +++ b/glfw/wl_client_side_decorations.c @@ -132,8 +132,10 @@ create_shadow_tile(_GLFWwindow *window) { free(st.data); st.data = NULL; if (!mask) return margin; - st.data = malloc(sizeof(st.data[0]) * st.stride * st.stride); - if (st.data) + // Fill a local buffer and only publish it to st.data once complete, this + // also avoids a false positive use-after-free warning from CodeQL + uint32_t *data = malloc(sizeof(data[0]) * st.stride * st.stride); + if (data) for (size_t y = 0; y < st.stride; y++) for (size_t x = 0; x < st.stride; x++) { double alpha = mask[y * st.stride + x]; @@ -148,9 +150,10 @@ create_shadow_tile(_GLFWwindow *window) { if (dx > 0 && dy > 0) distance = radius - hypot(dx, dy); double coverage = fmax(0, fmin(1, distance / feather)); alpha *= coverage * coverage * (3 - 2 * coverage); - st.data[y * st.stride + x] = ((uint32_t)(alpha * 255)) << 24; + data[y * st.stride + x] = ((uint32_t)(alpha * 255)) << 24; } free(mask); + st.data = data; return margin; }