Skip to content

Commit a4a2f78

Browse files
committed
Fixed cppcheck-opensource#4659 (portability: address value / integer false positive)
1 parent 1e66e0b commit a4a2f78

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/check64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void Check64BitPortability::pointerassignment()
6868
if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) {
6969
enum { NO, INT, PTR, PTRDIFF } type = NO;
7070
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
71-
if ((type == NO || type == INT) && isaddr(tok2->variable()))
71+
if ((type == NO || type == INT) && Token::Match(tok2, "%var% [+;]") && isaddr(tok2->variable()))
7272
type = PTR;
7373
else if (type == NO && (tok2->isNumber() || isint(tok2->variable())))
7474
type = INT;

test/test64bit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ class Test64BitPortability : public TestFixture {
9595
" *p = 0;\n"
9696
"}\n");
9797
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str());
98+
99+
check("int f(const char *p) {\n" // #4659
100+
" return 6 + p[2] * 256;\n"
101+
"}");
102+
ASSERT_EQUALS("", errout.str());
98103
}
99104

100105
void structmember() {

0 commit comments

Comments
 (0)