1

simple buggy code file

$ 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;
}

run command & result with 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.

with clang

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

I can't understand that the warnning is genereted (maybe by the compiler?), but still why the scan-build is not working?

**** UPDATED 06/30/2021

I follow this tutorial, and finnaly get the "python" version of scan-build which is such a misunderstanding, the answer perfectly solved my problem, now is working now. https://github.com/rizsotto/scan-build

works now!

albert-hk
  • 19
  • 4

1 Answers1

0

Somehow you are invoking scan-build-py instead of scan-build.

In my Ubuntu 20.04, after installation (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*

If I use /usr/bin/scan-build-py-10, I get the same output as you.

If I use /usr/bin/scan-build-10 I get the expected output when analyzing your C program.

$ 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

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • @sagi I removed that sentence. The rest of the answer still stands and is correct and explained the problem OP asked about. Would you mind removing your downvote? – Ted Lyngmo Jun 08 '22 at 14:24
  • yes, but I would rephrase the answer to be something like : "you can try using scan-build-10 instead of scan-build-py-10" because he did not have a mistake, this tool is part of clang-tools – sagi Jun 08 '22 at 20:20
  • @sagi OP was using `scan-build` so changing the answer to say that he should use `scan-build-10` instead of `scan-build-py-10` doesn't make sense. Also, I already mention that it's part of `clang-tools` in the answer. – Ted Lyngmo Jun 08 '22 at 20:46
  • no, you mentioned the number `10`. I don't mind the version – sagi Jun 09 '22 at 03:18
  • @sagi I listed what the link from `scan-build` that OP used was resolved (by following the links) on my system after a fresh installation. I used `scan-build-py-10` instead of `scan-build-10` to replicate OP:s problem and came to the conclusion that somehow, on OP:s system, running `scan-build` actually invokes `scan-build-py-10` (or whatever version OP had) instead of `scan-build-10`. So, OP used the correct command but it linked to the wrong executable. This made it possible for OP to fix the installation to get the proper links. In OP:s words: _"the answer perfectly solved my problem"_. – Ted Lyngmo Jun 09 '22 at 04:59