panoramix: avoid null dereference in PanoramiXConsolidate()

Reported in #1817:

Error: GCC_ANALYZER_WARNING (CWE-476): [#def5]
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:820:5: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘root’
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:819:12: acquire_memory: this call could return NULL
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:820:5: danger: ‘root’ could be NULL: unchecked value from (1)
818|
819|       root = malloc(sizeof(PanoramiXRes));
820|->     root->type = XRT_WINDOW;
821|       defmap = malloc(sizeof(PanoramiXRes));
822|       defmap->type = XRT_COLORMAP;
Error: GCC_ANALYZER_WARNING (CWE-476): [#def6]

xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:822:5: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘defmap’
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:821:14: acquire_memory: this call could return NULL
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:822:5: danger: ‘defmap’ could be NULL: unchecked value from (1)
820|       root->type = XRT_WINDOW;
821|       defmap = malloc(sizeof(PanoramiXRes));
822|->     defmap->type = XRT_COLORMAP;
823|       saver = malloc(sizeof(PanoramiXRes));
824|       saver->type = XRT_WINDOW;

Error: GCC_ANALYZER_WARNING (CWE-476): [#def7]
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:824:5: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘saver’
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:823:13: acquire_memory: this call could return NULL
xwayland-24.1.6/redhat-linux-build/../Xext/panoramiX.c:824:5: danger: ‘saver’ could be NULL: unchecked value from (1)
822|       defmap->type = XRT_COLORMAP;
823|       saver = malloc(sizeof(PanoramiXRes));
824|->     saver->type = XRT_WINDOW;
825|
826|       FOR_NSCREENS(i) {

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2065>
This commit is contained in:
Alan Coopersmith 2025-09-20 16:45:59 -07:00
parent 537b56ccca
commit 23c103d41f

View file

@ -817,11 +817,11 @@ PanoramiXConsolidate(void)
for (i = 0; i < pScreen->numVisuals; i++)
PanoramiXMaybeAddVisual(pVisual++);
root = malloc(sizeof(PanoramiXRes));
root = XNFcallocarray(1, sizeof(PanoramiXRes));
root->type = XRT_WINDOW;
defmap = malloc(sizeof(PanoramiXRes));
defmap = XNFcallocarray(1, sizeof(PanoramiXRes));
defmap->type = XRT_COLORMAP;
saver = malloc(sizeof(PanoramiXRes));
saver = XNFcallocarray(1, sizeof(PanoramiXRes));
saver->type = XRT_WINDOW;
FOR_NSCREENS(i) {