从终端进行 iPhone 静态代码分析未能找到丢失的 ivar 版本

发布于 2024-10-08 07:51:55 字数 1398 浏览 3 评论 0原文

我有一个在终端中运行的脚本,该脚本在我的 iPhone 应用程序上运行扫描构建代码分析器来检查问题。我只是偶然注意到,至少有一个实例没有找到未在 dealloc 方法中释放的 IBOutlet ivar。

以下是我从终端运行的命令的内容:

#!/bin/sh
cd /Developer/svn/MyCompany/iPhone/MyApplication
scan-build -analyzer-check-dead-stores -analyzer-check-llvm-conventions -analyzer-check-objc-mem -analyzer-check-objc-methodsigs -analyzer-check-objc-missing-dealloc -analyzer-check-objc-unused-ivars -analyzer-check-security-syntactic --experimental-checks -k -V -o scan-reports xcodebuild -configuration Debug -sdk iphonesimulator4.2 clean build

我已更新到 checker 的最新版本,因此不可能有较新版本的 checker。以下是我的类的 .h 文件的相关部分:

@interface LoginWizardUsernameViewController : UIViewController <UITextFieldDelegate, GetUserExistsDidFinish> {

 IBOutlet UITextField *username;
 IBOutlet UIActivityIndicatorView *activityIndicatorView;

}

@property (nonatomic, retain) UITextField *username;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicatorView;

以下是 .m 文件的相关部分:

// lots o' code omitted here

@implementation LoginWizardUsernameViewController

@synthesize username;
@synthesize activityIndicatorView;

- (void)dealloc 
{
    [super dealloc];
}

正如您所看到的,这两个 IBOutlet 项没有被释放,但即使它们被列为保留在属性定义,检查器由于某种原因没有看到这一点。奇怪的是,我可以转到其他类的 .m 文件,并在 dealloc 方法中注释掉某个版本,并且 scan-build 在问题扫描结束时愉快地提醒我。我只是无法弄清楚这种特殊情况有什么不同。

I have a script that I run in terminal that runs the scan-build code analyzer on my iPhone applications to check for issues. I just noticed quite by accident that there is at least one instance where it is not finding an IBOutlet ivar that is not being released in the dealloc method.

Here is the contents of the command I run from the Terminal:

#!/bin/sh
cd /Developer/svn/MyCompany/iPhone/MyApplication
scan-build -analyzer-check-dead-stores -analyzer-check-llvm-conventions -analyzer-check-objc-mem -analyzer-check-objc-methodsigs -analyzer-check-objc-missing-dealloc -analyzer-check-objc-unused-ivars -analyzer-check-security-syntactic --experimental-checks -k -V -o scan-reports xcodebuild -configuration Debug -sdk iphonesimulator4.2 clean build

I have updated to the very latest version of checker, so it can't be that there is a newer version of checker. Here are the pertinent parts of the .h file for my class:

@interface LoginWizardUsernameViewController : UIViewController <UITextFieldDelegate, GetUserExistsDidFinish> {

 IBOutlet UITextField *username;
 IBOutlet UIActivityIndicatorView *activityIndicatorView;

}

@property (nonatomic, retain) UITextField *username;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicatorView;

And here are the pertinent parts of the .m file:

// lots o' code omitted here

@implementation LoginWizardUsernameViewController

@synthesize username;
@synthesize activityIndicatorView;

- (void)dealloc 
{
    [super dealloc];
}

As you can see, there is no release of the two IBOutlet items, but even though they are listed as retained in the property definition, checker is not seeing this for some reason. The strange thing is that I can go to the .m file of other classes and comment out a release in the dealloc method, and scan-build happily alerts me at the end of the scan of the problem. I just cannot figure out what is different about this particular situation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2024-10-15 07:51:55

这是 Clang 静态分析器中的一个 bug,由尝试修复不同的问题

基于源代码,Clang静态分析器将跳过-dealloc 检查任何包含 only 非指针 ivars 或 IBOutlet ivars 的类:

104   // Does the class contain any ivars that are pointers (or id<...>)?
105   // If not, skip the check entirely.
106   // NOTE: This is motivated by PR 2517:
107   //        http://llvm.org/bugs/show_bug.cgi?id=2517
108 
109  bool containsPointerIvar = false;
110  
111  for (ObjCInterfaceDecl::ivar_iterator I=ID->ivar_begin(), E=ID->ivar_end();
112       I!=E; ++I) {
113 
114    ObjCIvarDecl* ID = *I;
115    QualType T = ID->getType();
116 
117    if (!T->isObjCObjectPointerType() ||
118        ID->getAttr<IBOutletAttr>() || // Skip IBOutlets.
119        ID->getAttr<IBOutletCollectionAttr>()) // Skip IBOutletCollections.
120      continue;
121 
122    containsPointerIvar = true;
123    break;
124  }
125 
126  if (!containsPointerIvar)
127    return;

我怀疑如果您只需向类添加非 IBOutlet 属性,它就能正常工作。

This is a bug in the Clang static analyzer, caused by an attempt to fix a different issue.

Based on the source code, the Clang static analyzer will skip -dealloc checking for any class which contains only non-pointer ivars or IBOutlet ivars:

104   // Does the class contain any ivars that are pointers (or id<...>)?
105   // If not, skip the check entirely.
106   // NOTE: This is motivated by PR 2517:
107   //        http://llvm.org/bugs/show_bug.cgi?id=2517
108 
109  bool containsPointerIvar = false;
110  
111  for (ObjCInterfaceDecl::ivar_iterator I=ID->ivar_begin(), E=ID->ivar_end();
112       I!=E; ++I) {
113 
114    ObjCIvarDecl* ID = *I;
115    QualType T = ID->getType();
116 
117    if (!T->isObjCObjectPointerType() ||
118        ID->getAttr<IBOutletAttr>() || // Skip IBOutlets.
119        ID->getAttr<IBOutletCollectionAttr>()) // Skip IBOutletCollections.
120      continue;
121 
122    containsPointerIvar = true;
123    break;
124  }
125 
126  if (!containsPointerIvar)
127    return;

I suspect that it will work properly if you simply add a non-IBOutlet property to your class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文