diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-10-08 11:34:00 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-10-08 11:44:24 -0700 |
commit | a8c782571d3b2419404f3a623f4b5396cd5e7aa4 (patch) | |
tree | 223305e29f05cae0319d519860f22cb668290fb2 | |
parent | d44b8926620bf6d033062557441d1aa935a0ac02 (diff) |
_XkbInitAtoms: check for malloc() failure
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 <alan.coopersmith@oracle.com>
-rw-r--r-- | src/xkbatom.c | 10 |
1 files 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; } |