From 1e2842f3e5afa83d93cce0ca4762e7fba63cb6d5 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 6 May 2025 16:06:55 +0200 Subject: [PATCH] composite: silence some warnings on possible NULL dereference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unlikely to practically happen, but still safer to just check for sure. A simple zero-value test doesn't cost us much (on modern CPUs perhaps not even a full clock cycle). | ../composite/compalloc.c: In function ‘compRedirectWindow’: | ../composite/compalloc.c:167:35: warning: dereference of NULL ‘pClient’ [CWE-476] [-Wanalyzer-null-dereference] | 167 | ccw->id = FakeClientID(pClient->index); | | ~~~~~~~^~~~~~~ | ../composite/compalloc.c: In function ‘compUnredirectWindow’: | ../composite/compalloc.c:331:75: warning: dereference of NULL ‘pClient’ [CWE-476] [-Wanalyzer-null-dereference] | 331 | if (ccw->update == update && dixClientIdForXID(ccw->id) == pClient->index) { | | ~~~~~~~^~~~~~~ Signed-off-by: Enrico Weigelt, metux IT consult --- composite/compalloc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composite/compalloc.c b/composite/compalloc.c index 4a1243170..a3eb592bd 100644 --- a/composite/compalloc.c +++ b/composite/compalloc.c @@ -43,6 +43,8 @@ #include +#include "os/bug_priv.h" + #include "compint.h" static Bool @@ -133,6 +135,8 @@ compHandleMarkedWindows(WindowPtr pWin, WindowPtr pLayerWin) int compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update) { + BUG_RETURN_VAL(!pClient, BadMatch); + CompWindowPtr cw = GetCompWindow(pWin); CompClientWindowPtr ccw; CompScreenPtr cs = GetCompScreen(pWin->drawable.pScreen); @@ -323,6 +327,8 @@ compUnredirectWindow(ClientPtr pClient, WindowPtr pWin, int update) CompWindowPtr cw = GetCompWindow(pWin); CompClientWindowPtr ccw; + BUG_RETURN_VAL(!pClient, BadValue); + if (!cw) return BadValue;