Infer - Facebook製の静的コード解析ツール
いかなるソフトウェアであってもバグはつきものです。バグがなかったとしてもそれは単に見つからなかったり大きな問題につながらないだけで、いつかは露見することになります。 Facebookが作ったInferはそんなプログラミングコードを静的に解析するソフトウェアで、アプリのバグをいち早く発見するためのツールになります。
Inferの使い方
例えば以下のようなコードがあります。これはjavacでコンパイルできるコードです。
// Hello.java
class Hello {
int test() {
String s = null;
return s.length();
}
}
これをInferにかけるとエラーが表示されます。
$ infer -- javac Hello.java
Hello.java:5: error: NULL_DEREFERENCE
object s last assigned on line 4 could be null and is dereferenced at line 5
対応言語としてはJavaの他、Objective-C、C言語に対応しています。つまりスマートフォンアプリ開発向けと言えるでしょう。例えばObjective-Cの場合は以下のようにコマンドを実行します。
infer -- xcodebuild -target HelloWorldApp -configuration Debug -sdk iphonesimulator
そうするとメモリリークしている場所も発見できます。
4 files analyzed
/usr/local/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:20: error: MEMORY_LEAK
memory dynamically allocated to shadowPath by call to CGPathCreateWithRect() at line 20, column 28 is not reachable after line 20, column 5
/usr/local/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:25: error: RESOURCE_LEAK
resource acquired to fp by call to fopen() at line 25, column 8 is not released after line 25, column 5
/usr/local/infer/examples/ios_hello/HelloWorldApp/AppDelegate.m:29: warning: PARAMETER_NOT_NULL_CHECKED
Parameter callback is not checked for null, there could be a null pointer dereference: pointer callback could be null and is dereferenced at line 29, column 5
:
Inferを使えば標準のコンパイラとは別でコードのチェックを行ってくれるようになります。アプリをリリースする前に一回チェックを行っておくことでアプリの品質が格段に向上するはずです。
InferはMac OSX/Linux用のオープンソース・ソフトウェア(BSD License)です。