Cppcheck with microsoft compiler extensions

Viewed 121

The code below uses the microsoft compiler extensions __try and __leave:

void f()
{
  char* a = nullptr;
  __try {
    a = (char*) malloc(10);
    if(!a) __leave;
    a[1];
  } __finally {}
}

Currently the code above gives the following warning:

(warning) Either the condition '!a' is redundant or there is possible null pointer dereference: a.

So the problem seem to be that cppcheck does not understand that __leave leaves the block if a is null. Replacing it by a 'return' cause the warning to go away.

Is it possible to make cppcheck understand this? The cppcheck manual states:

You can check non-standard code that includes various compiler extensions, inline assembly code, etc.

but I didn't find any further information about that.

Note, I am not looking for changing the code to make cppcheck happy but to make cppcheck understand the existing code.

0 Answers
Related