iPhone 应用程序上的 Clang 静态分析器显示最新版本的错误
当我通过版本 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 语句中的所有代码行。例如:
我想这可能是最新版本中引入的一些错误导致这些显示为错误的检查器。我在这里可能会遗漏其他内容(某种构建设置或扫描构建脚本的问题)吗?
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:
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,方法名称应以小写字母开头,而不是大写字母(除了 URL 等缩写)。静态分析器可能会被大写的“Get”绊倒。
接下来,即使使用小写的“get”,该方法也不遵循约定。
引用文档:
因此,分析器正确识别了问题。
我建议遵循指南并使用类似的东西:
这将释放一个自动释放的数组。如果由于某种原因无法返回自动释放的对象,请发表评论。
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:
Thus, the analyzer is correctly identifying an issue.
I would suggest following the guidelines and using something like:
Which would release an autoreleased array. If there is some reason you can't return an autoreleased object, please comment.