Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.11 KB

c6397.md

File metadata and controls

38 lines (29 loc) · 1.11 KB
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Warning C6397: The address-of operator cannot return null pointer in well-defined code
Warning C6397
02/05/2024
C6397
DUBIOUS_NULL_CHECK
C6397

Warning C6397

The address-of operator cannot return null pointer in well-defined code

Remarks

The address-of operator returns the address of its operand. This value should never be compared to nullptr:

  • The address-of a field can only be nullptr if the base pointer was nullptr and the field is at the zero offset (&p->field == nullptr implies p == nullptr). In this case, the expression should be simplified.
  • In any other cases, the value of the unary & operator can't be nullptr unless there's undefined behavior in the code (&v == nullptr always evaluates to false).

Example

bool isNull(int *a)
{  
    return &a == nullptr; // C6397 reported here.
}

To fix this issue, double check if the use of unary & was intentional:

bool isNull(int *a)
{  
    return a == nullptr; // no C6397 reported here.
}

See also

C6398