From 0d22aac7bb50ff1f7588f78ec25e9fb62a7b2e5e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Dec 2022 09:17:56 -0800 Subject: FindKeypadVMod: check xkb is not NULL before dereference, not after As found by cppcheck: vmod.c:232:26: warning: Either the condition 'xkb' is redundant or there is possible null pointer dereference: xkb. [nullPointerRedundantCheck] name = XkbInternAtom(xkb->dpy, "NumLock", False); ^ vmod.c:233:10: note: Assuming that condition 'xkb' is not redundant if ((xkb) && LookupVModIndex((XPointer) xkb, None, name, TypeInt, &rtrn)) ^ vmod.c:232:26: note: Null pointer dereference name = XkbInternAtom(xkb->dpy, "NumLock", False); ^ Signed-off-by: Alan Coopersmith --- vmod.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vmod.c b/vmod.c index af71704..97448c0 100644 --- a/vmod.c +++ b/vmod.c @@ -226,13 +226,14 @@ LookupVModMask(XPointer priv, int FindKeypadVMod(XkbDescPtr xkb) { - Atom name; - ExprResult rtrn; + if (xkb) { + Atom name = XkbInternAtom(xkb->dpy, "NumLock", False); + ExprResult rtrn; - name = XkbInternAtom(xkb->dpy, "NumLock", False); - if ((xkb) && LookupVModIndex((XPointer) xkb, None, name, TypeInt, &rtrn)) - { - return rtrn.ival; + if (LookupVModIndex((XPointer) xkb, None, name, TypeInt, &rtrn)) + { + return rtrn.ival; + } } return -1; } -- cgit v1.2.3