dix: protect against alloc failure in ‘DeviceFocusEvent()

Fixes analyzer warning:

| ../dix/enterleave.c: In function ‘DeviceFocusEvent’:
| ../dix/enterleave.c:788:20: warning: dereference of possibly-NULL ‘xi2event’ [CWE-690] [-Wanalyzer-possible-null-dereference]
|   788 |     xi2event->type = GenericEvent;
|   ‘DoFocusEvents’: events 1-4

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-06 13:55:54 +02:00
parent 6a8ee31e1b
commit e3a213f63c

View File

@ -771,7 +771,6 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
WindowPtr pWin)
{
deviceFocus event;
xXIFocusInEvent *xi2event;
int btlen, len, i;
DeviceIntPtr mouse = InputDevIsFloating(dev) ?
@ -783,7 +782,10 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
btlen = bytes_to_int32(btlen);
len = sizeof(xXIFocusInEvent) + btlen * 4;
xi2event = calloc(1, len);
xXIFocusInEvent *xi2event = calloc(1, len);
if (!xi2event)
return;
xi2event->type = GenericEvent;
xi2event->extension = IReqCode;
xi2event->evtype = type;