title: how to generate reports for C code with clang
body: <p>Following the directions from the main clang static analyzer web page (<a href="http://clang-analyzer.llvm.org/scan-build.html" rel="noreferrer">http://clang-analyzer.llvm.org/scan-build.html</a>)...</p>
  
  <p>I have a small C file that is heinously bug-ridden (<code>badcode.c</code>):</p>
  
  <pre><code>int main(int argc, char ** argv)
  {
      int j;
      int a[4];
      puts(a[j]);
      return 'a';
  }
  </code></pre>
  
  <p>In order to get a basic idea how the clang static analyzer (scan-build) words, I run:</p>
  
  <p><code>scan-build -v clang badcode.c</code></p>
  
  <p>It outputs:</p>
  
  <pre><code>scan-build: Emitting reports for this run to '/tmp/scan-build-2012-08-17-1'.
  scan-build: 'clang' executable not found in '/usr/share/clang/scan-build/bin'.
  scan-build: Using 'clang' from path: /usr/bin/clang
  badcode.c:7:2: warning: implicit declaration of function 'puts' is invalid in C99 [-Wimplicit-function-declaration]
          puts(a[j]);
          ^
  1 warning generated.
  scan-build: Removing directory '/tmp/scan-build-2012-08-17-1' because it contains no reports.
  </code></pre>
  
  <p>Ok, great, clang gives a little warning, but a.out is still produced. And how come it doesn't produce a report? The unititialized variable <code>j</code> should be a painfully obvious red flag to any static analyzer -- why isn't it reported?</p>
  
  <p>Am I simply using the wrong command line arguments?</p>