From: Christophe CURIS <[email protected]>

As pointed by Coverity, the allocated value returned by XGetModifierMapping
is assumed to be non-NULL everywhere except when releasing it.
Removed this last check (useless) and added a little check at the beginning
to avoid an (improbable) crash.

Signed-off-by: Christophe CURIS <[email protected]>
---
 WPrefs.app/xmodifier.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/WPrefs.app/xmodifier.c b/WPrefs.app/xmodifier.c
index 226652e..1845ada 100644
--- a/WPrefs.app/xmodifier.c
+++ b/WPrefs.app/xmodifier.c
@@ -119,7 +119,7 @@ static void x_reset_modifier_mapping(Display * display)
        int super_bit = 0;
        int alt_bit = 0;
        int mode_bit = 0;
-       XModifierKeymap *x_modifier_keymap = XGetModifierMapping(display);
+       XModifierKeymap *x_modifier_keymap;
 
 #define modwarn(name,old,other)                                                
        \
     wwarning ("%s (0x%x) generates %s, which is generated by %s.",             
\
@@ -155,6 +155,12 @@ static void x_reset_modifier_mapping(Display * display)
     else                                                                       
\
     old = modifier_index;
 
+       x_modifier_keymap = XGetModifierMapping(display);
+       if (x_modifier_keymap == NULL) {
+               wwarning("XGetModifierMapping returned NULL, there is no 
modifiers or no memory.\n");
+               return;
+       }
+
        mkpm = x_modifier_keymap->max_keypermod;
        for (modifier_index = 0; modifier_index < 8; modifier_index++)
                for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
@@ -270,8 +276,7 @@ static void x_reset_modifier_mapping(Display * display)
        AltIndex = alt_bit;
        ModeIndex = mode_bit;
 
-       if (x_modifier_keymap != NULL)
-               XFreeModifiermap(x_modifier_keymap);
+       XFreeModifiermap(x_modifier_keymap);
 }
 
 int ModifierFromKey(Display * dpy, const char *key)
-- 
1.9.2


-- 
To unsubscribe, send mail to [email protected].

Reply via email to