We have a die
function that outputs an error message and exits, e.g.:
void die(const char* msg) {
fprintf(stderr, "Error: %s\n", msg);
exit(1);
}
We use Parasoft C++test to statically analyze our code, but it doesn't realize that die
is a non-returning function. So when it sees code like:
void foo(Bar* bar) {
if(!bar) {
die("bar is NULL");
}
Bar bar2 = *bar;
}
It warns that *bar
might be dereferencing a null pointer, even though bar
being NULL would prevent that line from ever executing. Is there a way to mark die
as non-returning in a way Parasoft would recognize?
Edit: I need something that works in both GCC and VS 2003, but I'm not above #ifdef
ing my way around things if somebody has a solution that only works in VS
I figured it out. It turns out Parasoft has a built-in list of NRFs you can customize; they're called "terminating functions". You can edit them through the VS GUI or through the configuration file if you run Parasoft outside of VS
Test Configurations
dialog from the C++test
menuStatic
tabBugDetective Options
subtabSelect the Terminators
sub-subtab
Screenshot of the window http://so.mrozekma.com/parasoft1.png
Add a new entry with the non-returning function name
Screenshot of the entry http://so.mrozekma.com/parasoft2.png
Add lines like the following:
com.parasoft.xtest.checker.flowanalysis.terminators.api0.methods=active\=true|name\=die|type\=*|paramsn\=*|defsInSubClasses\=true;
com.parasoft.xtest.checker.flowanalysis.terminators.apis=active\=true|name\=foo;