Warning C26488
Don't dereference a pointer that may be null.
void ex1()
{
int* px = nullptr;
if (px) // notice the condition is incorrect
return;
*px = 1; // 'px' known to be null here
}
Remarks
The Lifetime guidelines from the C++ core guidelines outline a contract that code can follow which will enable more thorough static memory leak and dangling pointer detection. The basic ideas behind the guidelines are:
- Never dereference an invalid (dangling) or known-null pointer.
- Never return (either formal return or out parameter) any pointer from a function.
- Never pass an invalid (dangling) pointer to any function.