'...' could be '0': this does not adhere to the specification for the function '...'
다음과 같은 코드를 컴파일하면,
LPVOID hInstance = ::LoadLibrary(L"...");
PIMAGE_NT_HEADERS ntHeader = ImageNtHeader(hInstance);
Visual Studio 편집기 창에서 ImageNtHeader 코드에 빨간 줄을 그어 이런 식의 경고를 냅니다.
6387: 'hInstance' could be '0': this does not adhere to the specification for the function 'ImageNtHeader'.
왜냐하면, Visual Studio의 C++ 정적 코드 분석기가 ImageNtHeader가 받아들이는 인자 타입이 포인터임을 알고 nullptr이 들어갈 수 있다고 판단하기 때문입니다. 따라서 이런 경우에는 명시적으로 null 체크를 하는 코드를 추가해야 합니다.
LPVOID hInstance = ::LoadLibrary(L"...");
if (hInstance != nullptr)
{
PIMAGE_NT_HEADERS ntHeader = ImageNtHeader(hInstance);
}
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]