VS2012 Code Analysis Warning C6011 not showing all potential dereferencing of null pointers

182 Views Asked by At

I'm working on a C program in Visual Studio. Recently, I turned on Code Analysis (All rules) and after some testing I realized that the warning C6011 (dereferencing of null pointer) is not working as I expected.

The following code returns a warning C6011

struct test_struct
{
    unsigned int    int_test;
};

void set_to_1000(struct test_struct* const test)
{
    if (test == NULL) {
        printf("Error\n");
    }
    test->int_test = 1000;
}

However, the following code does not return such a warning (same struct as above)

void set_to_1000(struct test_struct* const test)
{    
    test->int_test = 1000;
}

Throughout the program, NULL is in general an acceptable input parameter. Is there any setting I can turn on so that the second example also returns a warning C6011?

0

There are 0 best solutions below