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.
精彩评论