Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/check64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ static bool is32BitIntegerReturn(const Function* func, const Settings* settings)
return vt && vt->pointer == 0 && vt->isIntegral() && vt->typeSize(settings->platform) == 4;
}

static bool isFunctionPointer(const Token* tok)
{
if (!tok || !tok->variable())
return false;
return Token::Match(tok->variable()->nameToken(), "%name% ) (");
}

void Check64BitPortability::pointerassignment()
{
if (!mSettings->severity.isEnabled(Severity::portability))
Expand Down Expand Up @@ -120,7 +127,8 @@ void Check64BitPortability::pointerassignment()
!tok->astOperand2()->isNumber() &&
rhstype->pointer == 0U &&
rhstype->originalTypeName.empty() &&
rhstype->type == ValueType::Type::INT)
rhstype->type == ValueType::Type::INT &&
!isFunctionPointer(tok->astOperand1()))
assignmentIntegerToAddressError(tok);

// Assign pointer to integer..
Expand Down
6 changes: 6 additions & 0 deletions test/test64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class Test64BitPortability : public TestFixture {
" t.a[i][j] = new std::vector<int>;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("int f();\n" // #11522
"void g() {\n"
" int (*fp)() = *(int(*)())f;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void novardecl() {
Expand Down
Loading