Better Software - July/August 2008 - (Page 39) routine does not return to the calling code, an ASA-reported error of “not checking the error flag” after the error routine returns would be superfluous. Many ASA tools have the ability to be trained to ignore these types of implementation-specific errors. ASA tools can also be used by developers in the unittesting phase of a project. Some ASA tools can be seamlessly added as a tool bar of integrated development environments (IDEs) such as Eclipse and IBM Rational Application Developer. At the time of this writing, there were seventeen open source ASA tools (primarily lint types) and thirty-eight commercial ASA tools listed on wikipedia.org. The ASA tool used in our case studies classifies defects in four major categories: • Defects • Header file problems • Low-level interface problems • Security vulnerabilities At the time of the case studies, the tool was capable of detecting more than fifty-two defect types from coding style, memory management, and null pointer dereferences to weak cryptography and access problems. Depending on the application, some defect types will be more critical than others. The ASA tool Klocwork provides a mechanism for tailoring the defect types detected at build time. In fact, Klocwork also provides an application-programming interface that allows an organization to create highly customized code checkers. The case studies presented here focus only on the defect checkers that are shipped with the tool and should be adequate for the vast majority of applications. The types of defects detected are: • Coding style • Concurrency • Memory-management problems • Null pointer dereference • Use of uninitialized data There are eleven sub-types of defects found under coding style: • Assignment in condition • Inappropriate iterator usage • Inconsistent use of types • Invalid pointer arithmetic • Loss of data Memory Leak (mlk.must) 1 2 3 4 5 6 7 8 9 10 class A { void foo(); }; void A::foo() { int *ptr = new int; *ptr = 25; ptr = new int; *ptr = 35; } Klocwork produces a defect report like the following: mlk.must.cc:8:Error:Memory leak. Dynamic memory stored in ‘ptr’ allocated through function ‘new’ at line 6 is lost at line 8 mlk.must.cc:10:Error:Memory leak. Dynamic memory stored in ‘ptr’ Figure 1 Memory Leak (mlk.might) 1 2 3 4 5 6 7 8 void foobar(int i) { char *p = (char*)malloc(12); if(i) { p = NULL; } return; } Klocwork produces a defect report like the following: mlk.might.c:7:Error:Possible memory leak. Dynamic memory stored in ‘p’ Figure 2 • • • • • • Statement has no effect Suspicious semicolon Unreachable code Unused code Unused data Suspicious return values The types of header file problems detected are: • Cycle in include files • Missing include files • Unnecessary include files • Missing direct include files The types of low-level interface problems detected are: • Object defined in header and declared in header • External object defined in header • Static object defined in header • Duplicated header • File uses local declaration of object without using interface file • Usage of object without declaration There are seven sub-types of defects under memory management: • Attempt to use memory after free • Freeing mismatched memory • Freeing non-heap memory • Freeing unallocated memory • Inconsistent freeing of memory • Memory leak • Returning reference to local variable www.StickyMinds.com JULY/AUGUST 2008 BETTER SOFTWARE 39 http://wikipedia.org http://www.StickyMinds.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.