From 275bebde5c11f1bda20d16147db10e7cd6eadf64 Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 10:26:42 -0400 Subject: [PATCH 1/7] Remove garbage collection flag. --- FunctionFlip.xcodeproj/project.pbxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/FunctionFlip.xcodeproj/project.pbxproj b/FunctionFlip.xcodeproj/project.pbxproj index e27ec24..a480cd5 100644 --- a/FunctionFlip.xcodeproj/project.pbxproj +++ b/FunctionFlip.xcodeproj/project.pbxproj @@ -614,7 +614,6 @@ "$(inherited)", "\"$(SRCROOT)\"", ); - GCC_ENABLE_OBJC_GC = unsupported; GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = FunctionFlip_Prefix.pch; From f8199bcd633199620c63a0b457699ca1f6bee24b Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 10:27:00 -0400 Subject: [PATCH 2/7] Open in Xcode 10.3. --- FunctionFlip.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunctionFlip.xcodeproj/project.pbxproj b/FunctionFlip.xcodeproj/project.pbxproj index a480cd5..3e73426 100644 --- a/FunctionFlip.xcodeproj/project.pbxproj +++ b/FunctionFlip.xcodeproj/project.pbxproj @@ -425,7 +425,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1030; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "FunctionFlip" */; compatibilityVersion = "Xcode 3.2"; From 710e5dc82e6e79e27cd0cfff06e13fcd4d483d08 Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 10:53:11 -0400 Subject: [PATCH 3/7] Fix numeric conversion precision errors. --- DDHidLib/DDHidDevice.h | 2 +- DDHidLib/DDHidDevice.m | 2 +- DDHidLib/DDHidJoystick.h | 10 +++++----- DDHidLib/DDHidJoystick.m | 20 ++++++++++---------- DDHidLib/DDHidKeyboard.h | 2 +- DDHidLib/DDHidKeyboard.m | 2 +- DDHidLib/DDHidKeyboardBarcodeScanner.h | 2 +- DDHidLib/DDHidKeyboardBarcodeScanner.m | 2 +- DDHidLib/DDHidMouse.h | 2 +- DDHidLib/DDHidMouse.m | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DDHidLib/DDHidDevice.h b/DDHidLib/DDHidDevice.h index 40b9fdb..80d4cc8 100644 --- a/DDHidLib/DDHidDevice.h +++ b/DDHidLib/DDHidDevice.h @@ -45,7 +45,7 @@ BOOL mListenInExclusiveMode; DDHidQueue * mDefaultQueue; int mTag; - int mLogicalDeviceNumber; + NSUInteger mLogicalDeviceNumber; } - (id) initWithDevice: (io_object_t) device error: (NSError **) error; diff --git a/DDHidLib/DDHidDevice.m b/DDHidLib/DDHidDevice.m index f52fcab..6916041 100644 --- a/DDHidLib/DDHidDevice.m +++ b/DDHidLib/DDHidDevice.m @@ -287,7 +287,7 @@ - (NSString *) productName if ([self logicalDeviceCount] > 1) { productName = [productName stringByAppendingString: - [NSString stringWithFormat:@" #%d", mLogicalDeviceNumber + 1]]; + [NSString stringWithFormat:@" #%lu", mLogicalDeviceNumber + 1]]; } return productName; } diff --git a/DDHidLib/DDHidJoystick.h b/DDHidLib/DDHidJoystick.h index ebf20cc..aa50904 100644 --- a/DDHidLib/DDHidJoystick.h +++ b/DDHidLib/DDHidJoystick.h @@ -44,13 +44,13 @@ #pragma mark - #pragma mark StickElements - indexed accessors -- (unsigned int) countOfStickElements; +- (NSUInteger) countOfStickElements; - (DDHidElement *) objectInStickElementsAtIndex: (unsigned int)index; #pragma mark - #pragma mark PovElements - indexed accessors -- (unsigned int) countOfPovElements; +- (NSUInteger) countOfPovElements; - (DDHidElement *) objectInPovElementsAtIndex: (unsigned int)index; - (NSArray *) allElements; @@ -74,19 +74,19 @@ logicalDeviceNumber: (int) logicalDeviceNumber error: (NSError **) error; -- (int) logicalDeviceCount; +- (NSUInteger) logicalDeviceCount; #pragma mark - #pragma mark Joystick Elements -- (unsigned) numberOfButtons; +- (NSUInteger) numberOfButtons; - (NSArray *) buttonElements; #pragma mark - #pragma mark Sticks - indexed accessors -- (unsigned int) countOfSticks; +- (NSUInteger) countOfSticks; - (DDHidJoystickStick *) objectInSticksAtIndex: (unsigned int)index; - (void) addElementsToQueue: (DDHidQueue *) queue; diff --git a/DDHidLib/DDHidJoystick.m b/DDHidLib/DDHidJoystick.m index 34a8843..75e1d75 100644 --- a/DDHidLib/DDHidJoystick.m +++ b/DDHidLib/DDHidJoystick.m @@ -122,7 +122,7 @@ - (id) initLogicalWithDevice: (io_object_t) device mLogicalDeviceElements = [[NSMutableArray alloc] init]; [self initLogicalDeviceElements]; - int logicalDeviceCount = [mLogicalDeviceElements count]; + NSUInteger logicalDeviceCount = [mLogicalDeviceElements count]; if (logicalDeviceCount == 0) { return nil; @@ -151,7 +151,7 @@ - (void) dealloc mButtonElements = nil; } -- (int) logicalDeviceCount; +- (NSUInteger) logicalDeviceCount; { return [mLogicalDeviceElements count]; } @@ -167,7 +167,7 @@ - (NSArray *) buttonElements; return mButtonElements; } -- (unsigned) numberOfButtons; +- (NSUInteger) numberOfButtons; { return [mButtonElements count]; } @@ -175,7 +175,7 @@ - (unsigned) numberOfButtons; #pragma mark - #pragma mark Sticks - indexed accessors -- (unsigned int) countOfSticks +- (NSUInteger) countOfSticks { return [mSticks count]; } @@ -351,11 +351,11 @@ - (int) normalizeValue: (int) value forElement: (DDHidElement *) element; { int normalizedUnits = DDHID_JOYSTICK_VALUE_MAX - DDHID_JOYSTICK_VALUE_MIN; - int elementUnits = [element maxValue] - [element minValue]; + long elementUnits = [element maxValue] - [element minValue]; - int normalizedValue = (((int64_t)(value - [element minValue]) * normalizedUnits) / + long normalizedValue = (((int64_t)(value - [element minValue]) * normalizedUnits) / elementUnits) + DDHID_JOYSTICK_VALUE_MIN; - return normalizedValue; + return (int)normalizedValue; } - (int) povValue: (int) value @@ -373,7 +373,7 @@ - (int) povValue: (int) value // Do like DirectInput and express the hatswitch value in hundredths of a // degree, clockwise from north. - return 36000 / (max - min + 1) * (value - min); + return (int)(36000 / (max - min + 1) * (value - min)); } - (BOOL) findStick: (unsigned *) stick @@ -613,7 +613,7 @@ - (DDHidElement *) yAxisElement; #pragma mark - #pragma mark mStickElements - indexed accessors -- (unsigned int) countOfStickElements +- (NSUInteger) countOfStickElements { return [mStickElements count]; } @@ -626,7 +626,7 @@ - (DDHidElement *) objectInStickElementsAtIndex: (unsigned int)index #pragma mark - #pragma mark PovElements - indexed accessors -- (unsigned int) countOfPovElements; +- (NSUInteger) countOfPovElements; { return [mPovElements count]; } diff --git a/DDHidLib/DDHidKeyboard.h b/DDHidLib/DDHidKeyboard.h index fd9200d..6b142aa 100644 --- a/DDHidLib/DDHidKeyboard.h +++ b/DDHidLib/DDHidKeyboard.h @@ -44,7 +44,7 @@ - (NSArray *) keyElements; -- (unsigned) numberOfKeys; +- (NSUInteger) numberOfKeys; - (void) addElementsToQueue: (DDHidQueue *) queue; diff --git a/DDHidLib/DDHidKeyboard.m b/DDHidLib/DDHidKeyboard.m index f8f1f3b..fca51e4 100644 --- a/DDHidLib/DDHidKeyboard.m +++ b/DDHidLib/DDHidKeyboard.m @@ -86,7 +86,7 @@ - (NSArray *) keyElements; return mKeyElements; } -- (unsigned) numberOfKeys; +- (NSUInteger) numberOfKeys; { return [mKeyElements count]; } diff --git a/DDHidLib/DDHidKeyboardBarcodeScanner.h b/DDHidLib/DDHidKeyboardBarcodeScanner.h index 8504343..6573b01 100644 --- a/DDHidLib/DDHidKeyboardBarcodeScanner.h +++ b/DDHidLib/DDHidKeyboardBarcodeScanner.h @@ -48,7 +48,7 @@ - (NSArray *) keyElements; -- (unsigned) numberOfKeys; +- (NSUInteger) numberOfKeys; - (void) addElementsToQueue: (DDHidQueue *) queue; diff --git a/DDHidLib/DDHidKeyboardBarcodeScanner.m b/DDHidLib/DDHidKeyboardBarcodeScanner.m index 79ccd22..dbce041 100644 --- a/DDHidLib/DDHidKeyboardBarcodeScanner.m +++ b/DDHidLib/DDHidKeyboardBarcodeScanner.m @@ -95,7 +95,7 @@ - (NSArray *) keyElements; return mKeyElements; } -- (unsigned) numberOfKeys; +- (NSUInteger) numberOfKeys; { return [mKeyElements count]; } diff --git a/DDHidLib/DDHidMouse.h b/DDHidLib/DDHidMouse.h index d396aba..35bc9d8 100644 --- a/DDHidLib/DDHidMouse.h +++ b/DDHidLib/DDHidMouse.h @@ -53,7 +53,7 @@ - (NSArray *) buttonElements; -- (unsigned) numberOfButtons; +- (NSUInteger) numberOfButtons; - (void) addElementsToQueue: (DDHidQueue *) queue; diff --git a/DDHidLib/DDHidMouse.m b/DDHidLib/DDHidMouse.m index 48b88f3..d80de65 100644 --- a/DDHidLib/DDHidMouse.m +++ b/DDHidLib/DDHidMouse.m @@ -117,7 +117,7 @@ - (NSArray *) buttonElements; return mButtonElements; } -- (unsigned) numberOfButtons; +- (NSUInteger) numberOfButtons; { return [mButtonElements count]; } From b87ae7ff0b476fe72f148b343863bca1fe1b8654 Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 11:06:44 -0400 Subject: [PATCH 4/7] Use modern Objective-C literal syntax. --- DDHidLib/DDHidJoystick.m | 2 +- .../NSXReturnThrowError/NSXReturnThrowError.m | 12 +- FFHelperApp.m | 2 +- FFHelperAppController.m | 2 +- FFKeyLibrary.m | 106 +++++++++--------- 5 files changed, 61 insertions(+), 63 deletions(-) diff --git a/DDHidLib/DDHidJoystick.m b/DDHidLib/DDHidJoystick.m index 75e1d75..07820e5 100644 --- a/DDHidLib/DDHidJoystick.m +++ b/DDHidLib/DDHidJoystick.m @@ -233,7 +233,7 @@ - (void) initLogicalDeviceElements; if (usagePage == kHIDPage_GenericDesktop && (usageId == kHIDUsage_GD_Joystick || usageId == kHIDUsage_GD_GamePad)) { - [mLogicalDeviceElements addObject: [NSArray arrayWithObject: element]]; + [mLogicalDeviceElements addObject: @[element]]; } } } diff --git a/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m b/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m index 22f31a5..c8de1c1 100644 --- a/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m +++ b/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m @@ -96,11 +96,11 @@ void NSXMakeErrorImp(const char *objCType_, intptr_t result_, const char *file_, if (errorDomain) { *error_ = [NSError errorWithDomain:errorDomain code:errorCode - userInfo:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:file_], @"reportingFile", - [NSNumber numberWithInt:line_], @"reportingLine", - [NSString stringWithUTF8String:function_], @"reportingMethod", - [NSString stringWithUTF8String:code_], @"origin", - nil]]; + userInfo:@{ + @"reportingFile" : @(file_), + @"reportingLine" : @(line_), + @"reportingMethod" : @(function_), + @"origin" : @(code_), + }]; } } diff --git a/FFHelperApp.m b/FFHelperApp.m index 86e6786..e6209a7 100644 --- a/FFHelperApp.m +++ b/FFHelperApp.m @@ -157,7 +157,7 @@ - (void)listenForKeyEvents if (AXIsProcessTrustedWithOptions != NULL) { // 10.9 or higher - NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:(id)kCFBooleanFalse, kAXTrustedCheckOptionPrompt, nil]; + NSDictionary *options = @{ (__bridge NSString *)kAXTrustedCheckOptionPrompt : (id)kCFBooleanFalse }; eventTapTest = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0, eventMask, myCGEventCallback, NULL); if (!AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options) || !eventTapTest) { diff --git a/FFHelperAppController.m b/FFHelperAppController.m index 7508f3a..d0229f8 100644 --- a/FFHelperAppController.m +++ b/FFHelperAppController.m @@ -55,7 +55,7 @@ + (void) launchHelperApp { NSURL *helperAppURL = [NSURL fileURLWithPath:[FFHelperAppController pathToHelperApp]]; unsigned options = NSWorkspaceLaunchWithoutAddingToRecents | NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchAsync; - [[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObject:helperAppURL] + [[NSWorkspace sharedWorkspace] openURLs:@[helperAppURL] withAppBundleIdentifier:nil options:options additionalEventParamDescriptor:nil diff --git a/FFKeyLibrary.m b/FFKeyLibrary.m index e52adad..37ab94c 100644 --- a/FFKeyLibrary.m +++ b/FFKeyLibrary.m @@ -29,66 +29,64 @@ #include "NSDictionary+firstKeyForObject.h" #import "FFDefs.h" -#define N(X) [NSNumber numberWithInt:X] - static NSDictionary *keyDescriptions, *keyCodes, *specialCodes; @implementation FFKeyLibrary + (void)initialize { - keyDescriptions = [[NSDictionary alloc] initWithObjectsAndKeys: - @"Brightness Down", N(NX_KEYTYPE_BRIGHTNESS_DOWN), - @"Brightness Up", N(NX_KEYTYPE_BRIGHTNESS_UP), - @"Brightness Down", N(KG_BRIGHTNESS_DOWN_KEY), - @"Brightness Up", N(KG_BRIGHTNESS_UP_KEY), - @"Toggle Illumination", N(NX_KEYTYPE_ILLUMINATION_TOGGLE), - @"Illumination Down", N(NX_KEYTYPE_ILLUMINATION_DOWN), - @"Illumination Up", N(NX_KEYTYPE_ILLUMINATION_UP), - @"Rewind", N(NX_KEYTYPE_REWIND), - @"Play/Pause", N(NX_KEYTYPE_PLAY), - @"Fast-Forward", N(NX_KEYTYPE_FAST), - @"Mute", N(NX_KEYTYPE_MUTE), - @"Volume Down", N(NX_KEYTYPE_SOUND_DOWN), - @"Volume Up", N(NX_KEYTYPE_SOUND_UP), - @"Mirror Displays", N(NX_KEYTYPE_VIDMIRROR), - @"Exposé", N(KG_EXPOSE_KEY), - @"Dashboard", N(KG_DASHBOARD_KEY), - @"Launchpad", N(KG_LAUNCHPAD_KEY), - nil]; + keyDescriptions = @{ + @(NX_KEYTYPE_BRIGHTNESS_DOWN) : @"Brightness Down", + @(NX_KEYTYPE_BRIGHTNESS_UP) : @"Brightness Up", + @(KG_BRIGHTNESS_DOWN_KEY) : @"Brightness Down", + @(KG_BRIGHTNESS_UP_KEY) : @"Brightness Up", + @(NX_KEYTYPE_ILLUMINATION_TOGGLE) : @"Toggle Illumination", + @(NX_KEYTYPE_ILLUMINATION_DOWN) : @"Illumination Down", + @(NX_KEYTYPE_ILLUMINATION_UP) : @"Illumination Up", + @(NX_KEYTYPE_REWIND) : @"Rewind", + @(NX_KEYTYPE_PLAY) : @"Play/Pause", + @(NX_KEYTYPE_FAST) : @"Fast-Forward", + @(NX_KEYTYPE_MUTE) : @"Mute", + @(NX_KEYTYPE_SOUND_DOWN) : @"Volume Down", + @(NX_KEYTYPE_SOUND_UP) : @"Volume Up", + @(NX_KEYTYPE_VIDMIRROR) : @"Mirror Displays", + @(KG_EXPOSE_KEY) : @"Exposé", + @(KG_DASHBOARD_KEY) : @"Dashboard", + @(KG_LAUNCHPAD_KEY) : @"Launchpad", + }; - keyCodes = [[NSDictionary alloc] initWithObjectsAndKeys: - N(KG_KEY_F1), FF_F1_KEYID, - N(KG_KEY_F2), FF_F2_KEYID, - N(KG_KEY_F3), FF_F3_KEYID, - N(KG_KEY_F4), FF_F4_KEYID, - N(KG_KEY_F5), FF_F5_KEYID, - N(KG_KEY_F6), FF_F6_KEYID, - N(KG_KEY_F7), FF_F7_KEYID, - N(KG_KEY_F8), FF_F8_KEYID, - N(KG_KEY_F9), FF_F9_KEYID, - N(KG_KEY_F10), FF_F10_KEYID, - N(KG_KEY_F11), FF_F11_KEYID, - N(KG_KEY_F12), FF_F12_KEYID, - nil]; - specialCodes = [[NSDictionary alloc] initWithObjectsAndKeys: - N(NX_KEYTYPE_BRIGHTNESS_DOWN), FF_BRIGHTNESS_DOWN_ID_LAPTOP, - N(NX_KEYTYPE_BRIGHTNESS_UP), FF_BRIGHTNESS_UP_ID_LAPTOP, - N(KG_BRIGHTNESS_DOWN_KEY), FF_BRIGHTNESS_DOWN_ID_EXTERNAL, - N(KG_BRIGHTNESS_UP_KEY), FF_BRIGHTNESS_UP_ID_EXTERNAL, - N(NX_KEYTYPE_ILLUMINATION_TOGGLE), FF_ILLUMINATION_TOGGLE_ID, - N(NX_KEYTYPE_ILLUMINATION_DOWN), FF_ILLUMINATION_DOWN_ID, - N(NX_KEYTYPE_ILLUMINATION_UP), FF_ILLUMINATION_UP_ID, - N(NX_KEYTYPE_REWIND), FF_REWIND_ID, - N(NX_KEYTYPE_PLAY), FF_PLAYPAUSE_ID, - N(NX_KEYTYPE_FAST), FF_FASTFORWARD_ID, - N(NX_KEYTYPE_MUTE), FF_MUTE_ID, - N(NX_KEYTYPE_SOUND_DOWN), FF_VOLUME_DOWN_ID, - N(NX_KEYTYPE_SOUND_UP), FF_VOLUME_UP_ID, - N(NX_KEYTYPE_VIDMIRROR), FF_VIDEO_MIRROR_ID, - N(KG_EXPOSE_KEY), FF_EXPOSE_ID, - N(KG_DASHBOARD_KEY), FF_DASHBOARD_ID, - N(KG_LAUNCHPAD_KEY), FF_LAUNCHPAD_ID, - nil]; + keyCodes = @{ + FF_F1_KEYID : @(KG_KEY_F1), + FF_F2_KEYID : @(KG_KEY_F2), + FF_F3_KEYID : @(KG_KEY_F3), + FF_F4_KEYID : @(KG_KEY_F4), + FF_F5_KEYID : @(KG_KEY_F5), + FF_F6_KEYID : @(KG_KEY_F6), + FF_F7_KEYID : @(KG_KEY_F7), + FF_F8_KEYID : @(KG_KEY_F8), + FF_F9_KEYID : @(KG_KEY_F9), + FF_F10_KEYID : @(KG_KEY_F10), + FF_F11_KEYID : @(KG_KEY_F11), + FF_F12_KEYID : @(KG_KEY_F12), + }; + specialCodes = @{ + FF_BRIGHTNESS_DOWN_ID_LAPTOP : @(NX_KEYTYPE_BRIGHTNESS_DOWN), + FF_BRIGHTNESS_UP_ID_LAPTOP : @(NX_KEYTYPE_BRIGHTNESS_UP), + FF_BRIGHTNESS_DOWN_ID_EXTERNAL : @(KG_BRIGHTNESS_DOWN_KEY), + FF_BRIGHTNESS_UP_ID_EXTERNAL : @(KG_BRIGHTNESS_UP_KEY), + FF_ILLUMINATION_TOGGLE_ID : @(NX_KEYTYPE_ILLUMINATION_TOGGLE), + FF_ILLUMINATION_DOWN_ID : @(NX_KEYTYPE_ILLUMINATION_DOWN), + FF_ILLUMINATION_UP_ID : @(NX_KEYTYPE_ILLUMINATION_UP), + FF_REWIND_ID : @(NX_KEYTYPE_REWIND), + FF_PLAYPAUSE_ID : @(NX_KEYTYPE_PLAY), + FF_FASTFORWARD_ID : @(NX_KEYTYPE_FAST), + FF_MUTE_ID : @(NX_KEYTYPE_MUTE), + FF_VOLUME_DOWN_ID : @(NX_KEYTYPE_SOUND_DOWN), + FF_VOLUME_UP_ID : @(NX_KEYTYPE_SOUND_UP), + FF_VIDEO_MIRROR_ID : @(NX_KEYTYPE_VIDMIRROR), + FF_EXPOSE_ID : @(KG_EXPOSE_KEY), + FF_DASHBOARD_ID : @(KG_DASHBOARD_KEY), + FF_LAUNCHPAD_ID : @(KG_LAUNCHPAD_KEY), + }; } /* From 7b77a0ebf3d76f27f5075783691376e6d1dda9ba Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 11:08:34 -0400 Subject: [PATCH 5/7] Fix superclass/subclass integer type mismatch. --- DDHidLib/DDHidDevice.h | 2 +- DDHidLib/DDHidDevice.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DDHidLib/DDHidDevice.h b/DDHidLib/DDHidDevice.h index 80d4cc8..0e52c64 100644 --- a/DDHidLib/DDHidDevice.h +++ b/DDHidLib/DDHidDevice.h @@ -52,7 +52,7 @@ - (id) initLogicalWithDevice: (io_object_t) device logicalDeviceNumber: (int) logicalDeviceNumber error: (NSError **) error; -- (int) logicalDeviceCount; +- (NSUInteger) logicalDeviceCount; #pragma mark - #pragma mark Finding Devices diff --git a/DDHidLib/DDHidDevice.m b/DDHidLib/DDHidDevice.m index 6916041..057a0a5 100644 --- a/DDHidLib/DDHidDevice.m +++ b/DDHidLib/DDHidDevice.m @@ -169,7 +169,7 @@ + (NSArray *) allDevicesMatchingCFDictionary: (CFDictionaryRef) matchDictionary return devices; } -- (int) logicalDeviceCount; +- (NSUInteger) logicalDeviceCount; { return 1; } From 2a65ae40ee837703d0ccf0eab07b095619945e85 Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 11:27:23 -0400 Subject: [PATCH 6/7] Prevent potential crash when attempting to assign a null pointer. --- .../NSXReturnThrowError/NSXReturnThrowError.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m b/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m index c8de1c1..61ef0e1 100644 --- a/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m +++ b/DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m @@ -94,13 +94,16 @@ void NSXMakeErrorImp(const char *objCType_, intptr_t result_, const char *file_, } if (errorDomain) { - *error_ = [NSError errorWithDomain:errorDomain - code:errorCode - userInfo:@{ - @"reportingFile" : @(file_), - @"reportingLine" : @(line_), - @"reportingMethod" : @(function_), - @"origin" : @(code_), - }]; + if (error_ != nil) + { + *error_ = [NSError errorWithDomain:errorDomain + code:errorCode + userInfo:@{ + @"reportingFile" : @(file_), + @"reportingLine" : @(line_), + @"reportingMethod" : @(function_), + @"origin" : @(code_), + }]; + } } } From 09dbadf928c4eff6cb3059152326e78e534d4f12 Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Sat, 3 Aug 2019 11:27:50 -0400 Subject: [PATCH 7/7] Fix leaks identified by static analyzer. --- FFHelperApp.m | 5 ++++- FFKeyboard.m | 1 + USBNotifier.m | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/FFHelperApp.m b/FFHelperApp.m index e6209a7..ad9bde1 100644 --- a/FFHelperApp.m +++ b/FFHelperApp.m @@ -91,6 +91,7 @@ CGEventSourceRef sourceRef = CGEventCreateSourceFromEvent(ev); CGEventRef newEvent = CGEventCreateKeyboardEvent(sourceRef, [regularKey intValue], keyState); CFRelease(sourceRef); + CFAutorelease(newEvent); return newEvent; } } @@ -114,7 +115,6 @@ newE = [NSEvent otherEventWithType:NSSystemDefined location:[e locationInWindow] modifierFlags:([e modifierFlags] | ([e type] == NSKeyDown ? 0xa00 : 0xb00)) timestamp:[e timestamp] windowNumber:[e windowNumber] context:[e context] subtype:8 data1:(specialCode << 16) + (([e type] == NSKeyDown ? 0x0a : 0x0b) << 8) data2:-1]; } CGEventRef newEvent = [newE CGEvent]; - CFRetain(newEvent); // newEvent gets released by the event system return newEvent; } } @@ -204,6 +204,9 @@ - (void)listenForKeyEvents CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); + // Source is retained by the run loop. + CFRelease(runLoopSource); + // Enable the event tap. CGEventTapEnable(eventTap, true); diff --git a/FFKeyboard.m b/FFKeyboard.m index 9ade98c..737c1bd 100644 --- a/FFKeyboard.m +++ b/FFKeyboard.m @@ -55,6 +55,7 @@ - (id)initWithDevice:(DDHidKeyboard *)aDevice { CFStringRef fnusagemap = IORegistryEntrySearchCFProperty([self.device ioDevice], kIOServicePlane, (CFStringRef)@"FnFunctionUsageMap", kCFAllocatorDefault, kIORegistryIterateRecursively); if(fnusagemap) { // if we've got a non-special keyboard, this won't be set NSArray *codes = [(__bridge NSString *)fnusagemap componentsSeparatedByString:@","]; + CFRelease(fnusagemap); NSMutableArray *fkeyCodes = [NSMutableArray array]; NSMutableArray *specialCodes = [NSMutableArray array]; NSInteger index = 0; diff --git a/USBNotifier.m b/USBNotifier.m index 541ba58..2c8a390 100644 --- a/USBNotifier.m +++ b/USBNotifier.m @@ -64,10 +64,14 @@ static void usbDeviceRemoved(void *refCon, io_iterator_t iterator) { CFStringRef deviceName = CFStringCreateWithCString(kCFAllocatorDefault, deviceNameChars, kCFStringEncodingASCII); - if (CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) + if (CFStringCompare(deviceName, CFSTR("OHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) { + CFRelease(deviceName); deviceName = CFCopyLocalizedString(CFSTR("USB Bus"), ""); - else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) + } + else if (CFStringCompare(deviceName, CFSTR("EHCI Root Hub Simulation"), 0) == kCFCompareEqualTo) { + CFRelease(deviceName); deviceName = CFCopyLocalizedString(CFSTR("USB 2.0 Bus"), ""); + } // NSLog(@"USB Device Detached: %@" , deviceName); [(__bridge FFHelperApp *)refCon keyboardListChanged];