From c0c722b9f479412f27973ba0c4cd4a166dcb00be Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 8 Sep 2014 08:27:03 +0200 Subject: Bug 1065: Handle NULL result of TISGetInputSourceProperty(keyboard, kTISPropertyUnicodeKeyLayoutData), avoiding crash --- src/newt/native/NewtMacWindow.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/newt/native/NewtMacWindow.m') diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index 5a1963155..caf9e54e0 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -124,6 +124,9 @@ static CFStringRef CKCH_CreateStringForKey(CGKeyCode keyCode, const UCKeyboardLa static CFMutableDictionaryRef CKCH_CreateCodeToCharDict(TISInputSourceRef keyboard) { CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(keyboard, kTISPropertyUnicodeKeyLayoutData); + if( NULL == layoutData ) { + return NULL; + } const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData); CFMutableDictionaryRef codeToCharDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 128, NULL, NULL); @@ -149,8 +152,10 @@ static CFMutableDictionaryRef CKCH_USCodeToNNChar = NULL; static void CKCH_CreateDictionaries() { TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); - CKCH_USCodeToNNChar = CKCH_CreateCodeToCharDict(currentKeyboard); - CFRelease(currentKeyboard); + if( NULL != currentKeyboard ) { + CKCH_USCodeToNNChar = CKCH_CreateCodeToCharDict(currentKeyboard); + CFRelease(currentKeyboard); + } } static UniChar CKCH_CharForKeyCode(jshort keyCode) { -- cgit v1.2.3