I am getting an abrupt crash on a initWithFormat:arguments command; I suspect it depends on some memory issue as the crash is quite unreliable; I had this code since months and just today it started crashing! Is there some evident issue in my code leading to dangling references, I am not very familar with C structures in objective-c.
- (id)stringWithFormat:(NSString *)format array:(NSArray*) arguments{
if ([arguments count]==0) return format;
NSLog(@"argument counts %lu", (unsigned long)[arguments count]);
NSRange range = NSMakeRange(0, [arguments count]);
NSMutableData* data = [NSMutableData dataWithLength:sizeof(id) * [arguments count]];
[arguments getObjects:(__unsafe_unretained id *)data.mutableBytes range:range];
NSLog(@"format %@ arguments=%@", format, arguments);
NSString* result = [[NSString alloc] initWithFormat:format arguments:data.mutableBytes];
return result;
}
Format and parameters match, as I could see in the NSLog. This is the crash log:
Thread 0 Crashed: 0 libobjc.A.dylib 0x0000000102152fc5 0x10213a000 + 102341 1 Foundation 0x0000000101ad9137 0x101a99000 + 262455 2 CoreFoundation
0x0000000105278244 0x105273000 + 21060 3 CoreFoundation
0x00000001052b6913 0x105273000 + 276755 4 Foundation
0x0000000101ad80b2 0x101a99000 + 258226 5 inArrivoHD
0x00000001000041ea 0x100000000 + 16874 6 inArrivoHD
0x0000000100004445 0x100000000 + 17477 7 inArrivoHD
0x00000001000069f0 0x100000000 + 27120 8 inArrivoHD
0x0000000100006ef0 0x100000000 + 28400 9 libdispatch.dylib
0x000000010570c851 0x10570b000 + 6225 10 libdispatch.dylib
0x000000010571f72d 0x10570b000 + 83757 11 libdispatch.dylib
0x000000010570f3fc 0x10570b000 + 17404 12 CoreFoundation
0x0000000105351289 0x105273000 + 909961 13 CoreFoundation
0x000000010529e854 0x105273000 + 178260 14 CoreFoundation
0x000000010529dd83 0x105273000 + 175491 15 GraphicsServices
0x000000010236af04 0x102360000 + 44804 16 UIKit
0x0000000100ab3e33 0x100a9f000 + 85555 17 inArrivoHD
0x00000001000013a3 0x100000000 + 5027 18 libdyld.dylib
0x00000001059705fd 0x10596d000 + 13821