【Hacker News搬运】GCC 14中静态分析的改进
-
Title: Improvements to static analysis in GCC 14
GCC 14中静态分析的改进
Text:
Url: https://developers.redhat.com/articles/2024/04/03/improvements-static-analysis-gcc-14-compiler
该文章讨论了GCC 14编译器中-fanalyzer静态分析 pass的改进,该编译器将于2024年4月发布。-fanalyzer选项通过执行C源代码进行符号执行,以在编译时识别潜在问题。GCC 14的新功能包括使用-Wanalyzer-infinite-loop警告检测无限循环,使用基于文本的图表可视化缓冲区溢出,更好地跟踪C字符串操作以及改进污染分析。作者建议使用Compiler Explorer网站来测试GCC 14编译器的新功能。
Post by: dmalcolm
Comments:
quincepie: To me fanalyzer is one of GCC killer features over clang. It makes programming C much easier by explaining errors. The error messages also began to feel similar to Rust in terms of being developer friendly.
quincepie: 对我来说,fanalyzer是GCC的杀手级功能之一。它通过解释错误使编程C变得更加容易。在对开发人员友好方面,错误消息也开始感觉与Rust相似。
perihelions: 36 more comments in this other thread:<p><a href="https://news.ycombinator.com/item?id=39918278">https://news.ycombinator.com/item?id=39918278</a> (<i>"GCC 14 Boasts Nice ASCII Art for Visualizing Buffer Overflows (phoronix.com)"</i>, 2 hours ago)
perihelions: 另一个线程中还有36条评论:<p><a href=“https:/;新闻.ycombinator.com/?项目?id=39918278”>https:ȏ/;news.ycombinator.com/;项目id=39918278</a>(<i>“GCC 14承载用于可视化缓冲区溢出的漂亮ASCII艺术(phoronix.com)”</i> ,2小时前)
Davidbrcz: I wish there was a better output format for the analysis, because this is hell for screen readers.
Davidbrcz: 我希望有一个更好的分析输出格式,因为这对屏幕阅读器来说是地狱。
1udfx9cf8azi0: <p><pre><code> if (nbytes < sizeof(*hwrpb))
return -1;if (copy_to_user(buffer, hwrpb, nbytes) != 0) return -2;
</code></pre>
The fix that was done was:<p><pre><code> if (nbytes > sizeof(*hwrpb))
</code></pre>
But I think the correct fix is:<p><pre><code> if (copy_to_user(buffer, hwrpb, sizeof(*hwrpb)) != 0)
</code></pre>
It never makes sense to copy out of the hwrpb pointer any size other than sizeof(*hwrpb).1udfx9cf8azi0: <p><pre><code>if(nbytes<;sizeof(*hwrpb))return-1;if(copy_to_user(buffer,hwrpb,nbytes)!=0)return-2;</code></pre>所做的修复是:<p><pre><code>if(nbytes>;sizeof(*hwrpb))</code></pre>但我认为正确的修复方法是:<p><pre><code>if(copy_to_user(buffer,hwrpb,sizeof(*hwrpb))!=0)</code></pre>从hwrpb指针中复制除sizeof(*hwrpb)以外的任何大小都没有意义。
noam_k: Very cool stuff!<p>I haven't done much C development lately, so I'm curious how often
strcpy
andstrcat
are used. Last I checked they're almost as big no-nos as using goto. (Yes, I know goto is often preferred in kernel dev...) Can anyone share on how helpful the c-string analyses are to them?noam_k: 非常酷的东西<p> 我没有;最近没有做太多的C开发,所以我;我很好奇“strcpy”和“strcat”的使用频率。最后我检查了一下他们;re几乎和使用goto一样大。(是的,我知道goto在内核开发中通常是首选…)有人能分享一下c字符串分析对他们有多大帮助吗?