You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learn more about: C26488 LIFETIMES_DEREF_NULL_POINTER
title
C26488
ms.date
12/14/2018
ms.topic
conceptual
f1_keywords
C26488
helpviewer_keywords
C26488
ms.assetid
2ade0d31-f259-49de-8676-cce6092fabfc
author
kylereedmsft
ms.author
kylereed
C26488 LIFETIMES_DEREF_NULL_POINTER
Don't dereference a pointer that may be null.
voidex1()
{
int* px = nullptr;
if (px) // notice the condition is incorrectreturn;
*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.