Added support for member variables in Check64BitPortability::pointerassignment()

This commit is contained in:
PKEuS 2014-10-02 14:57:09 +02:00
parent 15f397ab18
commit 621644b17a
2 changed files with 12 additions and 7 deletions

View File

@ -96,18 +96,23 @@ void Check64BitPortability::pointerassignment()
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %var% = %var% [;+]")) { if (Token::Match(tok, "[;{}] %var% = %var%")) {
const Token* tok2 = tok->tokAt(3);
while (Token::Match(tok2->next(), ".|::"))
tok2 = tok2->tokAt(2);
if (!Token::Match(tok2, "%var% ;|+"))
continue;
const Variable *var1(tok->next()->variable()); const Variable *var1(tok->next()->variable());
const Variable *var2(tok->tokAt(3)->variable()); const Variable *var2(tok2->variable());
if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+") if (isaddr(var1) && isint(var2) && tok2->strAt(1) != "+")
assignmentIntegerToAddressError(tok->next()); assignmentIntegerToAddressError(tok->next());
else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare()) { else if (isint(var1) && isaddr(var2) && !tok2->isPointerCompare()) {
// assigning address => warning // assigning address => warning
// some trivial addition => warning // some trivial addition => warning
if (Token::Match(tok->tokAt(4), "+ %any% !!;")) if (Token::Match(tok2->next(), "+ %any% !!;"))
continue; continue;
assignmentAddressToIntegerError(tok->next()); assignmentAddressToIntegerError(tok->next());

View File

@ -103,11 +103,11 @@ private:
} }
void structmember() { void structmember() {
check("struct Foo { int *p };\n" check("struct Foo { int *p; };\n"
"void f(struct Foo *foo) {\n" "void f(struct Foo *foo) {\n"
" int i = foo->p;\n" " int i = foo->p;\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", "", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
} }
void ptrcompare() { void ptrcompare() {