Bug #350
closed
Assign property cause crash of application (Objective-C)
Added by Dmitry M. over 11 years ago.
Updated about 10 years ago.
Description
Code example is below:
@interface foo : BaseObject {
BOOL boolProperty;
id stringProperty;
}
@property (assign) BOOL boolProperty;
@property (copy) id stringProperty;
-(id) init;
-(void) bar;
@end
@implementation foo
@synthesize boolProperty;
@synthesize stringProperty;
- (void) bar
{
self.boolProperty = YES;
self.stringProperty = @"";
}
@end
- Assignee set to Alexander Z.
- Status changed from Open to In Progress
- % Done changed from 0 to 50
- Target version changed from r8-crystax-2 to 10.0.0
- Status changed from In Progress to Completed
- % Done changed from 0 to 100
Declaring property as 'copy' requires respective class to implement NSCoping protocol and thus implement copyWithZone method.
The issues's code example (slightly modified) compiled with GCC 4.6 correctly raises runtime exception (copyWithZone selector not found), but code compiled with GCC 4.8 or 4.9 just dumps core.
The described behavior can be reproduced on any Linux box with GCC Objective C compiler or Clang with GNU objc runtime.
To prevent application crash one needs either not declare property as 'copy' or implement copyWithZone method.
See test/device/crystax-issue-350-copy-with-zone sample code.
Also available in: Atom
PDF