From c9820b2ba50cacc5fbeeb6a9c71f5e544bd45dee Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:20:31 +0200 Subject: [PATCH] Fixed issues found with static analysis. --- src/cocoa_joystick.m | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 45b3be0f..c0268e44 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -336,7 +336,12 @@ void _glfwInitJoysticks(void) result = IOMasterPort(bootstrap_port, &masterPort); hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey); if (kIOReturnSuccess != result || !hidMatchDictionary) + { + if (hidMatchDictionary) + CFRelease(hidMatchDictionary); + return; + } result = IOServiceGetMatchingServices(masterPort, hidMatchDictionary, @@ -370,19 +375,27 @@ void _glfwInitJoysticks(void) /* Check device type */ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) + { CFNumberGetValue(refCF, kCFNumberLongType, &usagePage); + if (usagePage != kHIDPage_GenericDesktop) + { + /* We are not interested in this device */ + continue; + } + } refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) - CFNumberGetValue(refCF, kCFNumberLongType, &usage); - - if ((usagePage != kHIDPage_GenericDesktop) || - (usage != kHIDUsage_GD_Joystick && - usage != kHIDUsage_GD_GamePad && - usage != kHIDUsage_GD_MultiAxisController)) { - /* We don't interested in this device */ - continue; + CFNumberGetValue(refCF, kCFNumberLongType, &usage); + + if ((usage != kHIDUsage_GD_Joystick && + usage != kHIDUsage_GD_GamePad && + usage != kHIDUsage_GD_MultiAxisController)) + { + /* We are not interested in this device */ + continue; + } } _glfwJoystick* joystick = &_glfwJoysticks[deviceCounter];