Using SoftBench CodeAdvisor

6

Using SoftBench CodeAdvisor

SoftBench CodeAdvisor provides advanced code checking for C and C++. SoftBench CodeAdvisor (available in C++ SoftBench) can help you find and fix a variety of subtle and dangerous errors that most C and C++ compilers can not detect. SoftBench CodeAdvisor does not duplicate the error-checking functions of the compilers. The compilers check for many syntactic and some logic problems, but are limited to checking for fairly simple, localized problems.

SoftBench CodeAdvisor can check for much more complex and far-reaching problems, including problems that cross compilation units (two separately compiled programs linked together). Using SoftBench CodeAdvisor you can find problems such as potential heap corruption, dangling pointers, ambiguous initializations, and dependencies on system-specific compiler/linker behavior.

SoftBench CodeAdvisor also helps you to make your programs faster, more reliable, and more portable by alerting you to actual and potential code problems. SoftBench CodeAdvisor uses specific rules to identify potential problems. Each rule is a set of instructions that queries the SoftBench Static database for the information of interest, and then performs a test for the presence of an error condition. When SoftBench CodeAdvisor detects an error (rule violation), it displays the violation's location in an output browser. The browser helps you navigate to the problem and use a preconfigured editor to correct the error.

SoftBench CodeAdvisor helps especially with C++ programs since C++ performs many activities "behind the scenes." For example, it automatically and invisibly calls class constructors when you create a new instance of a class. C++ calls destructors when an instance goes out of scope and is no longer valid. This transparent functionality allows C++ to perform many of the operations that make it so useful.

However, because C++ does so much for you, you may not be completely aware of some of the things the software does. As a result, you may unintentionally write your program in a way that could cause problems.

For example, C++ allows you to define an assignment operator, operator=, on your classes. Your operator= should free any memory allocated by the class before copying the new class value into it. However, if the assignment actually assigns the class to itself (classA = classA),

Chapter 6

145