开发者

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

开发者 https://www.devze.com 2022-12-31 13:27 出处:网络
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.

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 reta开发者_开发百科inCount + 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?


Your code looks correct in both cases. For no. 2, you're probably confusing the analyzer by using performSelector instead of plain initWithAdditive (is there a particular reason you're using a selector?). I'm not sure about no. 1, but maybe try initializing it with [[[UILabel alloc] init...] autorelease] instead of autoreleasing separately, and see if the problem persists.

0

精彩评论

暂无评论...
验证码 换一张
取 消