From 266d9a2945c11aa6c79d558a0b05898a325c8568 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 31 May 2014 19:58:48 +0200 Subject: [PATCH] WPrefs: fix NULL pointer handling when getting the Modifiers (Coverity #50200) 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 --- 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 226652e5..1845ada4 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) -- 2.11.4.GIT