iPhone 应用程序上的 Clang 静态分析器显示最新版本的错误

发布于 2024-10-10 18:43:59 字数 838 浏览 5 评论 0原文

当我通过版本 252 检查器二进制文件运行代码时,没有分析错误。但是,当我更改为使用最新的 253 检查器时,它返回大量错误,所有这些错误都没有任何意义。例如,以下是 scan-build 脚本完成后在我的 Safari 浏览器中显示的错误图像:

这是一个非常常见的错误,显示在错误列表中。正如您所看到的,方法名称末尾有 Copy,但它仍然报告为名称不正确。

以下是我现在使用检查器版本 253 时遇到的错误细分:

Bug Summary

Results in this analysis run are based on analyzer build checker-253.

Bug Type    Quantity
All Bugs    83  

Dead code   
Unreachable code    17  

Memory (Core Foundation/Objective-C)    
Bad release 19  
Leak of returned object 23  
Object sent -autorelease too many times 24

自动释放错误似乎与分析器无法看到 Copy 方法实际上已正确命名这一事实有关,我试图寻找一个示例无法访问的代码,但我无法真正找到这些错误的任何模式或解释,因为这些错误都是简单 if 语句中的所有代码行。例如:

Yet another Clanganalysiser error

我想这可能是最新版本中引入的一些错误导致这些显示为错误的检查器。我在这里可能会遗漏其他内容(某种构建设置或扫描构建脚本的问题)吗?

When I run my code through the version 252 checker binary, there are no analysis errors. However, when I change to use the latest 253 checker, it returns a slew of errors, all of which do not make any sense. For example, here is an image of an error that it shows in my Safari browser after the scan-build script is complete:

Clang static analyzer error

This is a pretty common error that shows up in the error listing. As you can see, the method name has Copy at the end of it, but it is still reporting as incorrectly named.

Here is the breakdown of errors that I am now getting with checker version 253:

Bug Summary

Results in this analysis run are based on analyzer build checker-253.

Bug Type    Quantity
All Bugs    83  

Dead code   
Unreachable code    17  

Memory (Core Foundation/Objective-C)    
Bad release 19  
Leak of returned object 23  
Object sent -autorelease too many times 24

The autorelease errors seem to be related to the fact that the analyzer is unable to see that the Copy methods are actually correctly named, and I tried to look for an example of unreachable code, but I could not really find any patterns or explanations of those errors, as the errors were all lines of code inside simple if statements. Here is one for example:

Yet another Clang analyzer error

I suppose that this could be some bugs that were introduced in the latest version of checker that is causing these to show up as errors. Is there something else (some kind of build setting or issue with the scan-build script) that I could be missing here?

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

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

发布评论

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

评论(1

不离久伴 2024-10-17 18:43:59

首先,方法名称应以小写字母开头,而不是大写字母(除了 URL 等缩写)。静态分析器可能会被大写的“Get”绊倒。

接下来,即使使用小写的“get”,该方法也不遵循约定。

引用文档:

仅对返回的方法使用“get”
间接的对象和值。你
应该仅将此形式用于方法
当需要多个项目时
返回。

因此,分析器正确识别了问题。

我建议遵循指南并使用类似的东西:

+ (NSArray *) modifiedOrNewPeople: (FMDatabase *) aDatabase;

这将释放一个自动释放的数组。如果由于某种原因无法返回自动释放的对象,请发表评论。

First, method names should start with lower case letters, not uppercase (save for abbreviations like URL). It may be that the static analyzer is tripping over the uppercase "Get".

Next, even with a lowercase "get", the method does not follow convention.

To quote the documentation:

Use “get” only for methods that return
objects and values indirectly. You
should use this form for methods only
when multiple items need to be
returned.

Thus, the analyzer is correctly identifying an issue.

I would suggest following the guidelines and using something like:

+ (NSArray *) modifiedOrNewPeople: (FMDatabase *) aDatabase;

Which would release an autoreleased array. If there is some reason you can't return an autoreleased object, please comment.

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