Question

I'm using coverity (5.5.1) (among others) to harden my code. I stumbled over a problem and now I have doubts that my setup of coverity is not complete. Have a look at this example:

class A
{
    int _a,_b;
public:
    A(int b) : _a(_b), _b(b)
    { }
};

int main(void)
{
    A *a1 = new A(5);
    delete a1;

    A a2(5);
    return 0;
}

As can be seen I'm using _b to initialize _a before it is initialized with b. In this question I learned that it would be "nice to have" such a warning issued by the compiler or any other tool.

Contrarily to my original understanding of the problem I now found out, that coverity actually emits a defect which matches perfectly (UNINT), but only when allocated on the stack, not when created with new. So in my main-function I get the warning for A a2(5) but not for A *a1 = new A(5).

It seems to me that coverity is handling the call to the constructor different when using new than when the object created on the stack.

Is there anything I overlooked in my coverity configuration? What can I do to have the warning when allocated on the heap?

Was it helpful?

Solution

It turned out that according to the support this is a known bug in Coverity (even in the current version). A fix might arrive with the version released the following summer.

The bug is listed under the ID: 50128 UNINIT FN: member used in constructor before initialization and will as such be put into the release-notes when fixed and released.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top