Skip to content

Commit 9d88cc6

Browse files
amai2012danmar
authored andcommitted
Fixed cppcheck-opensource#4642 (False positive: Returning an address value in a function with integer return type is not portable. (not returning address))
1 parent 3d1cdd0 commit 9d88cc6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/check64bit.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ void Check64BitPortability::pointerassignment()
7777
else if (Token::Match(tok2, "%type% (")) {
7878
type = NO;
7979
break;
80-
} else if (tok2->str() == ";")
80+
} else if (type == PTR && Token::simpleMatch(tok2, "."))
81+
type = NO; // Reset after pointer reference, see #4642
82+
else if (tok2->str() == ";")
8183
break;
8284
}
8385

test/test64bit.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ class Test64BitPortability : public TestFixture {
180180
" return a + 1 - b;\n"
181181
"}");
182182
ASSERT_EQUALS("", errout.str());
183+
184+
check("struct s {\n" // 4642
185+
" int i;\n"
186+
"};\n"
187+
"int func(struct s *p) {\n"
188+
" return 1 + p->i;\n"
189+
"}");
190+
ASSERT_EQUALS("", errout.str());
183191
}
184192
};
185193

0 commit comments

Comments
 (0)