int* ptrF();
void f()
{
int* p = ptrF();
bool pOK = p && true;
if (pOK)
*p = 12; // Lint thinks p might be nullptr here
}
Lint gives a warning
C:\lint_test\nullptr_with_init.cpp(8): Issue 613: (Warning -- Possible use of null pointer 'p' in argument to operator 'unary *' [Reference: file C:\lint_test\nullptr_with_init.cpp: line 6])
Does anyone know if there is a setting to make Lint more "clever" and to see that pOK cannot be true if p == nullptr?
This would be much better than changing the code or suppressing the warning like this
*p = 12; //lint !e613
Edit:
Pc Lint, how to suppress err 613(Possible use of null ponter) for class with init() is an absolutely different question. That one is about how to supress a warning. This one is about how to make Lint check "complicated" if-statements (if possible)
I seems like in this case adding conversion from pointer to bool will help
bool pOK = (bool)p && true;