微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

scan-build 不工作报告“正在删除目录 xxx,因为它不包含任何报告”

如何解决scan-build 不工作报告“正在删除目录 xxx,因为它不包含任何报告”

简单的错误代码文件

$ 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.

hello.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 日更新

我按照本教程进行操作,最终得到了 scan-build 的“python”版本,这是一个误解,答案完美地解决了我的问题,现在可以使用了。 https://github.com/rizsotto/scan-build

works now!

解决方法

不知何故,您正在调用 scan-build-py 而不是 scan-build

这是一个旨在分析 python 代码的脚本。

在我的 Ubuntu 20.04 中,安装后 (sudo apt install clang-tools):

/usr/bin/scan-build -> scan-build-10*
/usr/bin/scan-build-10 -> ../share/clang/scan-build-10/bin/scan-build*
/usr/bin/scan-build-py-10 -> ../share/clang/scan-build-py-10/bin/scan-build*

如果我使用 /usr/bin/scan-build-py-10,我会得到和你一样的输出。

如果我使用 /usr/bin/scan-build-10,我会在分析您的 C 程序时得到预期的输出。

$ scan-build-10 -v gcc -o hello hello.c
scan-build: Using '/usr/lib/llvm-10/bin/clang' for static analysis
scan-build: Emitting reports for this run to '/tmp/scan-build-2021-06-29-065953-647-1'.
hello.c: In function ‘main’:
hello.c:2:15: warning: division by zero [-Wdiv-by-zero]
    2 |     int x = 7 / 0; // bug here
      |               ^
hello.c:2:9: warning: Value stored to 'x' during its initialization is never read
    int x = 7 / 0; // bug here
        ^   ~~~~~
hello.c:2:15: warning: Division by zero
    int x = 7 / 0; // bug here
            ~~^~~
2 warnings generated.
scan-build: 2 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2021-06-29-065953-647-1' to examine bug reports.
$ scan-view /tmp/scan-build-2021-06-29-065953-647-1

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。