Chromium Dioxide Chromium Dioxide - 1 year ago 138
Objective-C Question

Segmentation fault bridging CFErrorRef to NSError

I'm getting a crash in the follow code, where the bridge cast from CFErrorRef to NSError is.

Service exited due to signal: Segmentation fault: 11

CFErrorRef cfError = NULL;
ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef) spam.number, (__bridge CFStringRef) label, &cfError);
if (cfError != nil)
NSError *error = [[NSError alloc] initWithDomain:@"PlaceholderErrorDomain" code:-99999 userInfo: nil];
error = (__bridge NSError *)cfError;
NSLog(@"Error adding phone number to contact. %d %@", error.code, [error.userInfo description]);

After ABMultiValueAddValueAndLabel() executes the value of cfError is 0x1. Is this supposed to actually be a valid address of an allocated CFErrorRef object?

Any suggestions on the cause/fix of this?

Answer Source

Your primary issue is that the 4th parameter to ABMultiValueAddValueAndLabel is not an error. It's for getting back an identifier.

To see if the value was added or not, see if ABMultiValueAddValueAndLabel returns true or false. But you aren't given any information about why it failed if it does fail.

ABMultiValueIdentifier identifier;
if (!ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef) spam.number, (__bridge CFStringRef) label, &identifier) {
    // Unable to add value and label but there is no error to tell you why
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download