The code below uses the microsoft __try and __leave compiler extensions:
void f() { char* a = nullptr; __try { a = (char*) malloc(10); if(!a) __leave; a[1]; } __finally {} }
Currently, the above code gives the following warning:
(warning) Either the condition '!a' is redundant or there is possible null pointer dereference: a.
So the problem is that cppcheck does not understand that __leave leaves the block if a is null. Replacing it with a βreturnβ causes the warning to go away.
Is it possible to do cppcheck? The cppcheck manual states:
You can check non-standard code, which includes various compiler extensions, built-in assembler code, etc.
but I did not find additional information about this.
Notice I'm not looking for code changes to make cppcheck happy, but for cppcheck to understand the existing code.
source share