【发布时间】:2015-03-28 12:23:09
【问题描述】:
我有以下代码:
char *get_string_property_2(IOHIDDeviceRef device, CFStringRef prop)
{
CFStringRef str = IOHIDDeviceGetProperty(device, prop);
if(str)
{
CFIndex str_len = CFStringGetLength(str);
...
}
...
}
有时(并非总是)我在CFStringGetLength 中遇到崩溃,日志如下:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fff770083a8
Thread 8 Crashed:
0 libobjc.A.dylib 0x00007fff88e22097 objc_msgSend + 23
1 libtobii_usb.dylib 0x00000001081c4f72 get_string_property_2 + 130 (macosx.c:99)
2 serviced 0x00000001081a5fad device_removed_callback + 285 (daemond_mac.c:614)
3 libsystem_pthread.dylib 0x00007fff8ae35899 _pthread_body + 138
4 libsystem_pthread.dylib 0x00007fff8ae3572a _pthread_start + 137
5 libsystem_pthread.dylib 0x00007fff8ae39fc9 thread_start + 13
我该如何解决这个问题?在调用CFStringGetLength 之前,我正在检查 str 是否为 NULL,显然这还不够。
编辑:
我仍然遇到这种崩溃,总是在同一个地方。
如果它是一个坏指针,为什么不在IOHIDDeviceGetProperty 上面的一行崩溃??
还有其他方法可以获取CFStringRef 的长度吗?
我怀疑api有bug。
【问题讨论】:
标签: macos core-foundation