単純なバグのあるコード ファイル
$ python --version
Python 3.8.5
$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ clang --version
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ make --version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
こんにちはC
int main() {
int x = 7 / 0; // bug here
return 0;
}
gcc でコマンドと結果を実行する
$ scan-build -v gcc -o hello hello.c
scan-build: INFO: Report directory created: /tmp/scan-build-2021-06-29-03-50-40-733039-n821xtkx
hello.c: In function ‘main’:
hello.c:2:13: warning: division by zero [-Wdiv-by-zero]
2 | int x = 7 / 0; // Memory leak
| ^
scan-build: WARNING: Removing directory '/tmp/scan-build-2021-06-29-03-50-40-733039-n821xtkx' because it contains no report.
クランで
$ scan-build -v clang -o hello hello.c
scan-build: INFO: Report directory created: /tmp/scan-build-2021-06-29-03-51-08-738812-1059tk4t
hello.c:2:13: warning: division by zero is undefined [-Wdivision-by-zero]
int x = 7 / 0; // Memory leak
^ ~
1 warning generated.
scan-build: WARNING: Removing directory '/tmp/scan-build-2021-06-29-03-51-08-738812-1059tk4t' because it contains no report.
警告が生成されることを理解できません (おそらくコンパイラによるものでしょうか?) が、それでもスキャンビルドが機能しないのはなぜですか?
**** 2021 年 6 月 30 日更新
私はこのチュートリアルに従い、最終的に「python」バージョンのscan-buildを取得しましたが、これはそのような誤解であり、答えは私の問題を完全に解決し、現在は機能しています。 https://github.com/rizsotto/scan-build