rid
rid

Reputation: 63442

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.

Upvotes: 1

Views: 627

Answers (1)

rid
rid

Reputation: 63442

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

Upvotes: 1

Related Questions