Search code examples
cvisual-studioannotationsstatic-analysissal

Can I remove NULL and bounds checks if I use SAL?


How much can I rely on SAL? Do I need to do

NSTATUS my_func(_In_ int *p)
{
    if (NULL == p) {
        return STATUS_INVALID_PARAMETER;
    }
    *p = 1;
    return STATUS_SUCCESS;
}

or can I just do

NTSTATUS my_func(_In_ int *p)
{
    *p = 1;
    return STATUS_SUCCESS;
}

Solution

  • SAL only provides static checks at compile time. This assumes that all code involved has the appropriate annotations and has also been checked. This is okay internal to your application or module but be careful at boundaries with other libraries.