0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/plugins/mac-capture/mac-helpers.h
jp9000 6b8b5e5f64 mac-capture: Fix potential crash querying devices
I didn't check to see if the size of the string was 0, when it's 0 it
won't create the converted string and it'll send a null pointer to
CFStringGetCString, causing it to crash.
2015-01-05 14:11:33 -08:00

35 lines
685 B
C

#pragma once
#include <util/dstr.h>
static inline bool mac_success(OSStatus stat, const char *action)
{
if (stat != noErr) {
blog(LOG_WARNING, "%s failed: %d", action, (int)stat);
return false;
}
return true;
}
static inline bool cf_to_cstr(CFStringRef ref, char *buf, size_t size)
{
if (!ref) return false;
return (bool)CFStringGetCString(ref, buf, size, kCFStringEncodingUTF8);
}
static inline bool cf_to_dstr(CFStringRef ref, struct dstr *str)
{
size_t size;
if (!ref) return false;
size = (size_t)CFStringGetLength(ref);
if (!size)
return false;
dstr_resize(str, size);
return (bool)CFStringGetCString(ref, str->array, size+1,
kCFStringEncodingUTF8);
}