c - scan-build make does not detect any bugs -


i have simple .c file, obvious bugs inside it.

#include <stdio.h>  struct s {   int x; };  void f(struct s s){ }  void test() {   struct s s;   f(s); // warn }  int test2(int x){   return 5/(x-x); // warn }  int main(){   test();   test2(532);   printf("hej\r\r"); } 

i trying use clang's static code analyzer tool (scan-build) detect errors. when run tool directly on files, example using following command:

scan-build g++ -o 1 1.c

i intended output, including warning compiler mentions division 0.

scan-build: using '/usr/lib/llvm-3.8/bin/clang' static analysis

1.c: in function ‘int test2(int)’: 1.c:16:11: warning: division 0 [-wdiv-by-zero] return 5/(x-x); ^

1.c:16:11: warning: division 0 return 5/(x-x);

~^~~~~~ 1 warning generated. scan-build: 1 bug found. scan-build: run 'scan-view /tmp/scan-build-2016-07-11-152043-3028-1' examine bug reports.

now, trying put command simple makefile. contents of makefile are:

all: 1.c     g++ -o 1 1.c clean:     rm -f *.o 1 

however, whenever run scan-build make, using following command:

scan-build make

i still warning compiler, not scan-build tool!!!

scan-build: using '/usr/lib/llvm-3.8/bin/clang' static analysis

g++ -o 1 1.c

1.c: in function ‘int test2(int)’:

1.c:16:11: warning: division 0 [-wdiv-by-zero] return 5/(x-x);

^ scan-build: removing directory '/tmp/scan-build-2016-07-11-152326-3055-1' because contains no reports. scan-build: no bugs found.

i have observed same behavior in both c , c++ files. see had come across similar error in past (2012), proposed answer not seem work , seems refer c++ files anyway. clues?

scan-build works substituting cc variable. use in your makefile

cc=g++ all: 1.c         $(cc) -o 1 1.c clean:         rm -f *.o 1 

and works

scan-build: using '/usr/bin/clang' static analysis /usr/share/clang/scan-build/ccc-analyzer -o 1 1.c 1.c:16:17: warning: division 0         return 5/(x-x); // warn            ~^~~~~~ 1 warning generated. scan-build: 1 bugs found. scan-build: run 'scan-view /tmp/scan-build-2016-07-11-160529-5951-1'  examine bug reports. 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -