TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A hands-on introduction to static code analysis

185 pointsby dolftaxabout 5 years ago

6 comments

UncleMeatabout 5 years ago
It&#x27;s good to see discussions of static analysis, but I often feel that these blog posts do a disservice to the techniques. The post leads by mentioning applications like bugfinding and security vuln detection but the examples here are barely above local syntactic checks. This is the common scenario in the majority of blog posts I see about static analysis, probably because it is just much easier to put together a quick write up on AST-linting. Heck, this article has a diagram that directly states that an AST is the input to a static analysis module, but that is true only for some kinds of things!<p>AST level analysis is certainly useful. Everybody should be using some sort of style checker. But AST pattern matching is a <i>completely</i> different technique from the stuff used to do bugfinding that I worry that these blog posts will give the wrong impression about what static analysis can do and what it can&#x27;t do.<p>I&#x27;d love to see blog posts about interprocedural pointer analysis, for example.
评论 #23072066 未加载
评论 #23079322 未加载
评论 #23073617 未加载
saagarjhaabout 5 years ago
The kinds of analyses mentioned here are typically grouped under &quot;linting&quot;–more advanced static analysis tools will typically do things like dataflow analysis.
评论 #23073373 未加载
评论 #23071640 未加载
dtornabeneabout 5 years ago
Going to drop a toplevel comment and say while this is interesting (sincerely!) if people are interested in deeper tools&#x2F;techniques the book Practical Binary Analysis is excellent, it ends in taint checking, symbolic excution techniques and uses Pin. <a href="https:&#x2F;&#x2F;practicalbinaryanalysis.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;practicalbinaryanalysis.com&#x2F;</a><p>Also worth checking out is BAP, the Binary Analysis Platform, which is the successor project to Bit Blaze, and is one of the most fascinating binary analysis frameworks out there for my money. It was the only one of the darpa CGC entries that ran on real binaries, not the much less complicated ones developed specifically for the challenge.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;BinaryAnalysisPlatform&#x2F;bap" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BinaryAnalysisPlatform&#x2F;bap</a>
评论 #23077095 未加载
flohofwoeabout 5 years ago
Slightly tangential to what the article is about, but at least in the C&#x2F;C++ world, the most important change to make static analysis popular for &quot;the rest of us&quot; was probably Xcode&#x27;s decision to integrate clang analyzer right into the Xcode UI under a menu item (Xcode doesn&#x27;t do many things right, but this is definitely one of the very good features).<p>This way, analyzing the code is a simple &quot;button press&quot; and works out of the box on every Xcode project.<p>Soon after, Microsoft followed suit in Visual Studio (even though in my experience, the MS analyzer doesn&#x27;t catch quite as many things as the clang analyzer).<p>Before that, static analyzers were those no doubt useful but obscure &quot;magic tools&quot; which were very hard to integrate into an existing build process.<p>Even the most useful tool will be ignored when it is hard to use.
评论 #23071575 未加载
pwaiversabout 5 years ago
Thanks for this article, dolftax! I followed all the examples on my machine with no problem, and I learned some new stuff.<p>I have a question: how difficult is it to implement the ast? It seems like that the bulk of the work for this static code analysis.
评论 #23079009 未加载
评论 #23074691 未加载
ecuafloabout 5 years ago
For &quot;Detecting unused imports&quot;, why not record the line numbers on the first pass as well? Then we don&#x27;t need to traverse the tree again