Fixed #4659 (portability: address value / integer false positive)

This commit is contained in:
Daniel Marjamäki 2013-03-17 17:25:57 +01:00
parent 1e66e0b931
commit a4a2f78a7a
2 changed files with 6 additions and 1 deletions

View File

@ -68,7 +68,7 @@ void Check64BitPortability::pointerassignment()
if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) { if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) {
enum { NO, INT, PTR, PTRDIFF } type = NO; enum { NO, INT, PTR, PTRDIFF } type = NO;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if ((type == NO || type == INT) && isaddr(tok2->variable())) if ((type == NO || type == INT) && Token::Match(tok2, "%var% [+;]") && isaddr(tok2->variable()))
type = PTR; type = PTR;
else if (type == NO && (tok2->isNumber() || isint(tok2->variable()))) else if (type == NO && (tok2->isNumber() || isint(tok2->variable())))
type = INT; type = INT;

View File

@ -95,6 +95,11 @@ private:
" *p = 0;\n" " *p = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
check("int f(const char *p) {\n" // #4659
" return 6 + p[2] * 256;\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void structmember() { void structmember() {