Domanda

I am actually working on some changes to my application and klocwork keeps complaining me about one issue:

I have a struct, say

Struct A
{
  long x;
  bool b;
}

I have a pointer and it is assigned a return value from another function:

A* z= (A*) function.get();

if(!z->x)
{
  z->x= somevalue;
}

The klocwork keeps pointing to if(!z->x), saying that z is explicitly dereferenced.

Although my application works fine now, will it affect my application in a drastic way in future?

È stato utile?

Soluzione

You need to first check whether z is non-null before deferencing z and checking for z->x.

 if(z && !z->k)
     ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top