Excuse the ads! We need some help to keep our site up.

List

Clang Static Analyzer

Important Points to Consider

Slower than Compilation

False Positives

More Checks

Download

Install

Example

#include <stdio.h>
#include <stdlib.h> 

int main(void)
{
    char *p = malloc(1);
    *p = 'a'; 

    char c = *p; 

    printf("\n [%c]\n",c); 

    free(p);
    c = *p;
    return 0;
}
lazenca0x0@ubuntu:/tmp/test$ scan-build-3.7 gcc test.c 
scan-build: Using '/usr/lib/llvm-3.7/bin/clang' for static analysis
test.c:14:5: warning: Value stored to 'c' is never read
    c = *p;
    ^   ~~
test.c:14:9: warning: Use of memory after it is freed
    c = *p;
        ^~
2 warnings generated.
scan-build: 2 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2017-11-29-061740-71620-1' to examine bug reports.
lazenca0x0@ubuntu:/tmp/test$
lazenca0x0@ubuntu:/tmp/test$ scan-view-3.7 /tmp/scan-build-2017-11-29-061740-71620-1
Starting scan-view at: http://127.0.0.1:8181
  Use Ctrl-C to exit.
Scan-build resultsReport 1Report 2

Related site