Recently I got a few EXC_BAD_ACCESS crashes from firebase when calling [NSString stringWithFormat:]. The code snipped is as follows:
#define TYPE_A @"typeA"
#define TYPE_B @"typeB"
- (void)myMethod {
NSString *type;
if (condition1) {
type = TYPE_A;
} else if (condition2) {
type = TYPE_B;
}
if (type) {
NSString *message = [NSString stringWithFormat:@"Message: %@", type];
}
}
This snippet is very simple so the only cause I can guess is that when type is declared, it is assigned a garbage value.
However, I found out that someone claimed years ago that under ARC, object pointers like this will be set to nil.(See Link1 Link2) If this is true, maybe there's a bug in LLVM; if not, what caused this crash?