[iOS] initWithFormat:arguments: crash on x86_64 bit system
| Originator: | toma.todorov | ||
| Number: | rdar://27272801 | Date Originated: | 08-Jul-2016 09:00 AM |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | 10.11.5 (15F34) |
| Classification: | Crash | Reproducible: |
The NSString's constructor 'initWithFormat:arguments:' produces a crash on x86_64 archs.
The crash is reproducible on iOS simulator (iOS 9.0, iPhone 6 Plus, simulator 13A344) running on OS X El Capitan 10.11.5 (15F34).
The case is to have a method which produces a string from a given format and a list of arguments represented by NSArray. The idea is to convert the NSArray object to va_list and use the 'initWithFormat:arguments:' method. This works well on iOS devices, however it crashes on OS X.
Here are some code snippets that produce crash:
1.
[...]
NSMutableData *data = [NSMutableData dataWithLength:(sizeof(id) * args.count)];
[args getObjects:(__unsafe_unretained id *)data.mutableBytes range:NSMakeRange(0, args.count)];
NSString *result = [[NSString alloc] initWithFormat:dictionary[@"message"] arguments:data.mutableBytes]; // <--------- Produces a crash
[...]
2.
[...]
void *argList = malloc(sizeof(NSString *) * [arguments count]);
[arguments getObjects:( __unsafe_unretained id *)argList];
NSString *result = = [[NSString alloc] initWithFormat:formatString arguments:argList]; // <--------- Produces a crash
[...]
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!