A Few Billion Lines of Code: Using Static Analysis in the Real World
cacm.acm.org
cacm.acm.org
This was indeed a puzzling question. Some poking around exposed the following chain of events: the company's make used a novel format to print out the absolute path of the directory in which the compiler ran; our script misparsed this path, producing the empty string that we gave as the destination to the Unix "cd" (change directory) command, causing it to change to the top level of the system; it ran "rm -rf * " (recursive delete) during compilation to clean up temporary files; and the build process ran as root.
Interesting observation:
Parsing is considered a solved problem. Unfortunately, this view is naïve, rooted in the widely believed myth that programming languages exist.
The C language does not exist; neither does Java, C++, and C#. While a language may exist as an abstract idea, and even have a pile of paper (a standard) purporting to define it, a standard is not a compiler. What language do people write code in? The character strings accepted by their compiler. Further, they equate compilation with certification. A file their compiler does not reject has been certified as "C code" no matter how blatantly illegal its contents may be to a language scholar. Fed this illegal not-C code, a tool's C front-end will reject it. This problem is the tool's problem.
If you're using C and/or C++, it's a truly amazing tool, and chases down some very weird bugs.
As our upgrade method, we basically enabled serious tests a few at a time, fixed most of the problems that showed up as a result, and then later enabled a few more checks on slightly less serious bugs.
But I can see how it's hard to sell that in general. ACCESS was actually a pretty good, sophisticated user of Coverity in most ways, and it paid us back handsomely in code quality.
As a final example, a buffer overflow checker flagged a bunch of errors of the form
unsigned p[4];
...
p[4] = 1;
"No, ANSI lets you write 1 past the end of the array."After heated argument, the programmer said, "We'll have to agree to disagree." We could agree about the disagreement, though we couldn't quite comprehend it.
That is some Zen shit.