Search code examples
cclangstatic-analysisclang-static-analyzer

Clang Static Analyzer unexpected NULL pointer warning


I have the following code:

int s[4096];
unsigned char o = 0;

int main(void) {
    int *n;
    return ((char *) (s + o)) == 0 ? *n : 0;
}

When I run the Clang Static Analyzer on that code, it warns me that I'm dereferencing n because (char *) (s + o) is a null pointer, which it's not (I can even print it and get an address that's definitely not zero).

What am I missing?

Clang Analyzer screenshot

I'm noticing that removing the (char *) cast makes the warning disappear.


Solution

  • I was testing with the Clang Static Analyzer version 8. Version 10 no longer reports the warning.