Inside a singleton class's static member function, instead of using getInstance(), I used the static pointer member variable directly.
I did not null check it and it was null at run time, hence null pointer exception.
PC lint did not notify me of this. Usually it notifies me as Prio 2 warning : Possible use of null pointer.
Why did it not notify me?
class stClass
{
int m_value;
static stClass *s_instance;
stClass(int v = 0)
{
m_value = v;
}
public:
int get_value()
{
return m_value;
}
void set_value(int v)
{
m_value = v;
}
static stClass *getInstance()
{
if (!s_instance)
s_instance = new stClass;
return s_instance;
}
static void intentFunction()
{
printf("%d", s_instance->getValue()); // Null pointer exception here...
}
};