Was testing some code and found an error with the following lines:
NSString *stringA = @"C99";
NSString *stringB = (__bridge id)malloc(sizeof (stringA));
It is not necessary to alloc
a NSString
this way, of course, and I am not required to do that. Again I was just testing on something else and I happened to stumble upon this.
The error reads:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)
In the console:
(lldb)
To generalize, perhaps I should ask:
Could we alloc Objective-C objects through the use of malloc
?
Has someone encountered this before (which I doubt, because I don't think anyone who uses Objective-C would alloc
a NSString
this way), but rather than shoving it aside and call it a day, I thought I would ask and see if someone knows what the exact cause of this is and why.