From 12dc048a632d4c74fbd691dc7aaf7585cbbee287 Mon Sep 17 00:00:00 2001 From: rogerman Date: Wed, 13 Mar 2013 07:34:09 +0000 Subject: [PATCH] Cocoa Port: - Fix a crashing bug where making the build using Xcode 4 would crash on OS X versions earlier than v10.7 (missing _strnlen() function). --- .../userinterface/DisplayWindowController.mm | 11 +---------- .../src/cocoa/userinterface/InputManager.mm | 18 +++--------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/cocoa/userinterface/DisplayWindowController.mm index b0790b52d..dbb13d5d7 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.mm @@ -75,14 +75,6 @@ enum OGLVertexAttributeID OGLVertexAttributeID_TexCoord0 = 8 }; -#ifndef MAC_OS_X_VERSION_10_7 -// In Mac OS X, strnlen() is unsupported prior to v10.7, so define it here. -static size_t strnlen(const char *s, size_t n) -{ - const char *p = (const char *)memchr(s, 0, n); - return(p ? p-s : n); -} -#endif // MAC_OS_X_VERSION_10_7 @implementation DisplayWindowController @@ -1340,13 +1332,12 @@ static size_t strnlen(const char *s, size_t n) } } - if (strnlen(inputStr, INPUT_HANDLER_STRING_LENGTH*2) != 0) + if (inputStr[0] != '\0' && inputStr[0] != ':') { [[windowController emuControl] setStatusText:[NSString stringWithCString:inputStr encoding:NSUTF8StringEncoding]]; } CommandAttributesList cmdList = [inputManager generateCommandListUsingInputList:&inputList]; - if (cmdList.empty()) { return isHandled; diff --git a/desmume/src/cocoa/userinterface/InputManager.mm b/desmume/src/cocoa/userinterface/InputManager.mm index e9c579b27..236dc0d97 100644 --- a/desmume/src/cocoa/userinterface/InputManager.mm +++ b/desmume/src/cocoa/userinterface/InputManager.mm @@ -64,15 +64,6 @@ extern "C" #endif // !__LP64__ || MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -#ifndef MAC_OS_X_VERSION_10_7 -// In Mac OS X, strnlen() is unsupported prior to v10.7, so define it here. -static size_t strnlen(const char *s, size_t n) -{ - const char *p = (const char *)memchr(s, 0, n); - return(p ? p-s : n); -} -#endif // MAC_OS_X_VERSION_10_7 - #pragma mark - @implementation InputHIDDevice @@ -1199,8 +1190,7 @@ static std::tr1::unordered_map keyboardNameTable; / // All inputs require a device code and element code for mapping. If one or both are // not present, reject the input. - if (strnlen(inputAttr.deviceCode, INPUT_HANDLER_STRING_LENGTH) == 0 || - strnlen(inputAttr.elementCode, INPUT_HANDLER_STRING_LENGTH) == 0) + if (inputAttr.deviceCode[0] == '\0' || inputAttr.elementCode[0] == '\0') { continue; } @@ -1236,8 +1226,7 @@ static std::tr1::unordered_map keyboardNameTable; / // All inputs require a device code and element code for mapping. If one or both are // not present, reject the input. - if (strnlen(inputAttr->deviceCode, INPUT_HANDLER_STRING_LENGTH) == 0 || - strnlen(inputAttr->elementCode, INPUT_HANDLER_STRING_LENGTH) == 0) + if (inputAttr->deviceCode[0] == '\0' || inputAttr->elementCode[0] == '\0') { return didCommandDispatch; } @@ -1555,8 +1544,7 @@ InputAttributesList InputManagerEncodeHIDQueue(const IOHIDQueueRef hidQueue) size_t hidInputCount = hidInputList.size(); for (unsigned int i = 0; i < hidInputCount; i++) { - if (strnlen(hidInputList[i].deviceCode, INPUT_HANDLER_STRING_LENGTH) == 0 || - strnlen(hidInputList[i].elementCode, INPUT_HANDLER_STRING_LENGTH) == 0) + if (hidInputList[i].deviceCode[0] == '\0' || hidInputList[i].elementCode[0] == '\0') { continue; }