是否可以抑制 Xcode 4 静态分析器警告?
Xcode 4 静态分析器在我的代码中报告了一些误报。有什么办法可以压制他们吗?
The Xcode 4 static analyzer reports in my code some false positives. Is there any way to suppress them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了一个解决方案:可以通过以下方式避免误报(如 Apple 单例设计模式):
分析器不会分析这些预处理器指令之间的代码。
I found a solution: false positives (like the Apple singleton design pattern) can be avoided with:
Analyzer will not analyze the code between those preprocessor directives.
看一下这个页面,它展示了如何使用多个 #defines 来注释 Objective-C 方法和参数,以帮助静态分析器 (clang) 做正确的事情
http://clang-analyzer.llvm.org/annotations.html
从该页面:
Take a look at this page which shows how to use several #defines to annotate objective-c methods and parameters to help the static analyzer (clang) do the right thing
http://clang-analyzer.llvm.org/annotations.html
From that page:
查看我的答案 这里。您可以向文件添加编译标志,静态分析器将忽略它们。这对于您不关心的第 3 方代码可能更好,而不是您正在编写的第一方代码。
See my answer here. You can add a compile flag to the files and static analyzer will ignore them. This is probably better for 3rd party code you aren't concerned about, and not for first party code you are writing.
大多数时候,使用 CF_RETURNS_RETAINED 之类的东西并遵循“创建”规则对我来说是有效的,但我遇到了一个我无法抑制的情况。
最后通过查看llvm源代码找到了抑制分析器的方法:
https://llvm.org/svn/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
分配给静态数组不会抑制警告,但分配给普通的旧静态'sSuppressStaticAnalyzer'会。
顺便说一句,上述方法中,使用 CGLayerRef 是我发现重绘缓存图像的最快方法(除了 OpenGL 之外)。
most of the time, using things like CF_RETURNS_RETAINED and following the 'create' rule works for me, but I ran into a case I could NOT suppress.
Finally found a way to suppress the analyzer by looking at llvm source code:
https://llvm.org/svn/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
For some reason, assigning to a static array didn't suppress the warning, but assigning to a plain old static 'sSuppressStaticAnalyzer' does.
By the way the above method, using CGLayerRef is the fastest way I've found to redraw cached images (besides OpenGL).