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 the C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION C++ Core Guidelines Checker warning. Don't pass an invalid pointer as a parameter.
title
C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION
ms.date
04/29/2022
ms.topic
reference
f1_keywords
C26486
helpviewer_keywords
C26486
ms.assetid
d5395efc-5eb2-4e82-9b45-fcd5ff4577bf
author
kylereedmsft
ms.author
kylereed
ms.custom
kr2b-contr-experiment
C26486 LIFETIMES_FUNCTION_PRECONDITION_VIOLATION
Don't pass a pointer that may be invalid (dangling) as a parameter to a function.
voiduse(int*);
voidex1()
{
int* px;
{
int x;
px = &x;
}
use(px); // px is a dangling pointer
}
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.