LLVM/Clang bug found in convenience method and NSClassFromString(...) alloc/release

Posted by pirags on Stack Overflow See other posts from Stack Overflow or by pirags
Published on 2010-05-17T12:51:40Z Indexed on 2010/05/17 13:00 UTC
Read the original article Hit count: 135

I am analyzing Objective-C iPhone project with LLVM/Clang static analyzer. I keep getting two reported bugs, but I am pretty sure that the code is correct.

1) Convenience method.

+ (UILabel *)simpleLabel
{
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 200, 25)];
  label.adjustsFontSizeToFitWidth = YES;
  [label autorelease]; // Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected.
  return label;
}

2) The [NSClassFromString(...) alloc] returns retainCount + 1. Am I right?

Class detailsViewControllerClass = 
    NSClassFromString(self.detailsViewControllerName);

UIViewController *detailsViewController = 
    [[detailsViewControllerClass alloc]
        performSelector:@selector(initWithAdditive:) withObject:additive];

[self.parentController.navigationController 
    pushViewController:detailsViewController animated:YES];
[detailsViewController release]; // Incorrect decrement of the reference count of an object is not owned...

Are these some Clang issues or I am totally mistaken in these both cases?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c