From a8c782571d3b2419404f3a623f4b5396cd5e7aa4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 8 Oct 2023 11:34:00 -0700 Subject: _XkbInitAtoms: check for malloc() failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handles gcc 12 analyzer warning: xkbatom.c: In function ‘_XkbInitAtoms’: xkbatom.c:194:21: warning: dereference of possibly-NULL ‘nodeTable’ [CWE-690] [-Wanalyzer-possible-null-dereference] 194 | nodeTable[None] = (NodePtr) NULL; | ^ Signed-off-by: Alan Coopersmith --- src/xkbatom.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/xkbatom.c b/src/xkbatom.c index 3e8b9c0..b6feac6 100644 --- a/src/xkbatom.c +++ b/src/xkbatom.c @@ -100,7 +100,7 @@ typedef struct _Node { static Atom lastAtom = None; static NodePtr atomRoot = (NodePtr) NULL; static unsigned long tableLength; -static NodePtr *nodeTable; +static NodePtr *nodeTable = NULL; static Atom _XkbMakeAtom(const char *string, size_t len, Bool makeit) @@ -191,7 +191,8 @@ _XkbInitAtoms(void) { tableLength = InitialTableSize; nodeTable = (NodePtr *) _XkbAlloc(InitialTableSize * sizeof(NodePtr)); - nodeTable[None] = (NodePtr) NULL; + if (nodeTable != NULL) + nodeTable[None] = (NodePtr) NULL; } /***====================================================================***/ @@ -239,11 +240,8 @@ XkbChangeAtomDisplay(Display *oldDpy, Display *newDpy, Atom atm) void XkbInitAtoms(Display *dpy) { - static int been_here = 0; - - if ((dpy == NULL) && (!been_here)) { + if ((dpy == NULL) && (nodeTable == NULL)) { _XkbInitAtoms(); - been_here = 1; } return; } -- cgit v1.2.3