Search code examples
c++static-analysisparasoft

How to mark a function as non-returning in Parasoft C++test?


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 #ifdefing my way around things if somebody has a solution that only works in VS


Solution

  • 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

    Through Visual Studio

    Through the configuration file

    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;