Fix #12422 (False positive: subtracting pointers in same struct)#5971
Conversation
| " (void)y[1];\n" | ||
| " (void)y[2];\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:9]: (error) The address of local variable 'a' is accessed at non-zero index.\n" |
There was a problem hiding this comment.
It's unfortunate that it does not warn anymore but I feel the implementation and message was sloppy:
- Variable 'a' is not a local variable. The message should not say that it's "local".
- I guess it should have warned about 's.a' instead. "address of 'a'" is not correct.
- It does not matter if it is a local or global variable what is important is that it's a plain int variable.
- Because the lifetime is irrelevant I am skeptic about using the lifetime values in the checker wouldn't it be better to rely on tokvalue?
There was a problem hiding this comment.
about these comments: I created ticket https://trac.cppcheck.net/ticket/12428 so we can act on those later when we have time.
| else if (vartok->str() == "." || vartok->str() == "::") | ||
| else if (vartok->str() == ".") | ||
| vartok = vartok->astOperand1(); | ||
| else if (vartok->str() == "::") |
There was a problem hiding this comment.
I think this change makes sense overall, though there maybe some places expecting a variable(ie getLifetimeVariable). So I was always concerned about causing issues, but it looks like only one test failed.
There was a problem hiding this comment.
Ah wait nevermind, this is changing a.x to point to a instead of x. I thought it was changing it to point to a.x. This would be a better change, but I guess there is a lot more test failures.
For a quick fix, it seems like #5970 is a better solution for a quick fix.
No description provided.