fix(mac): correct memory width mismatch in keyCodeForChar

This commit is contained in:
PekingSpades 2025-12-31 20:58:49 +08:00
parent 82a1a0ffc7
commit 5b3aecc1f8

View file

@ -470,7 +470,6 @@ CFStringRef createStringForKey(CGKeyCode keyCode)
CGKeyCode keyCodeForChar(const char c)
{
static CFMutableDictionaryRef charToCodeDict = NULL;
CGKeyCode code;
UniChar character = c;
CFStringRef charStr = NULL;
@ -495,9 +494,15 @@ CGKeyCode keyCodeForChar(const char c)
charStr = CFStringCreateWithCharacters(kCFAllocatorDefault, &character, 1);
/* Our values may be NULL (0), so we need to use this function. */
if (!CFDictionaryGetValueIfPresent(charToCodeDict, charStr,
(const void **)&code)) {
/* Our values may be NULL (0), so we need to use this function.
* Use a pointer-sized variable to receive the value, since CFDictionary
* stores values as void pointers (64-bit on modern systems), then cast
* to CGKeyCode (uint16_t). */
const void *value = NULL;
CGKeyCode code;
if (CFDictionaryGetValueIfPresent(charToCodeDict, charStr, &value)) {
code = (CGKeyCode)(uintptr_t)value;
} else {
code = UINT16_MAX;
}