简体   繁体   中英

C26486 - Don't pass a pointer that may be invalid to a function?

I'm developing a kernel driver for Windows and I recently decided to transition from C to C/C++. During my code transformation, I encounter a warning that I can't solve. Basically, I have a function with this particular line of code:

OB_PREOP_CALLBACK_STATUS
OCPreOperationCallback(
    _In_ PVOID RegistrationContext,
    _Inout_ POB_PRE_OPERATION_INFORMATION OperationInformation
    )
{
    // ...
    auto test = IoThreadToProcess(static_cast<PETHREAD>(OperationInformation->Object));
    // ...
}

This line is highlited with the error message as follows:

Warning C26486 Don't pass a pointer that may be invalid to a function. Parameter 0 '(*OperationInformation).Object' in call to 'IoThreadToProcess' may be invalid (lifetime.3).

The warning seems pretty clear: I need to make sure the pointer I pass as an argument is valid. Nevertheless, I could not find any way to check for an invalid state. I tried to add:

if(OperationInformation != nullptr && OperationInformation->Object != nullptr)

before the assignment, but the warning is still present.

Did I miss something regarding this issue?

PETHREAD pThread = static_cast<PETHREAD>(OperationInformation->Object);
if(pThread != nullptr) //or 'pThread != NULL' or 'pThread'
{
   auto test = IoThreadToProcess(pThread);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM