简体   繁体   English

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

[英]Clang static analyzer on iPhone app showing errors with latest version

When I run my code through the version 252 checker binary, there are no analysis errors. 当我通过版本252检查器二进制文件运行我的代码时,没有分析错误。 However, when I change to use the latest 253 checker, it returns a slew of errors, all of which do not make any sense. 但是,当我更改为使用最新的253检查程序时,它会返回一系列错误,所有错误都没有任何意义。 For example, here is an image of an error that it shows in my Safari browser after the scan-build script is complete: 例如,以下是扫描构建脚本完成后在Safari浏览器中显示的错误图像:

Clang静态分析仪错误

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: 以下是我使用检查器版本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. 自动释放错误似乎与分析器无法看到复制方法实际上正确命名的事实有关,我试图寻找无法访问代码的示例,但我无法找到任何模式或解释错误,因为错误是简单if语句中的所有代码行。 Here is one for example: 这是一个例子:

又一个Clang分析仪错误

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. 我想这可能是最新版本的checker中引入的一些错误导致这些错误显示为错误。 Is there something else (some kind of build setting or issue with the scan-build script) that I could be missing here? 是否有其他东西(某种构建设置或扫描构建脚本的问题),我可能会在这里丢失?

First, method names should start with lower case letters, not uppercase (save for abbreviations like URL). 首先,方法名称应以小写字母开头,而不是大写字母(除了URL之类的缩写)。 It may be that the static analyzer is tripping over the uppercase "Get". 可能是静态分析器在大写“Get”上跳闸。

Next, even with a lowercase "get", the method does not follow convention. 接下来,即使使用小写“get”,该方法也不遵循惯例。

To quote the documentation: 引用文档:

Use “get” only for methods that return objects and values indirectly. 仅对间接返回对象和值的方法使用“get”。 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. 如果您有某些原因无法返回自动释放的对象,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM