Fixed #3073 (False positive: Assigning an integer (int/long/etc) to a pointer is not portable)

This commit is contained in:
Daniel Marjamäki 2011-09-04 13:03:29 +02:00
parent 85d83d86ac
commit c34b77cebf
2 changed files with 24 additions and 1 deletions

View File

@ -58,7 +58,7 @@ void Check64BitPortability::pointerassignment()
const Variable *var1(symbolDatabase->getVariableFromVarId(tok->tokAt(1)->varId()));
const Variable *var2(symbolDatabase->getVariableFromVarId(tok->tokAt(3)->varId()));
if (isaddr(var1) && isint(var2))
if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+")
assignmentIntegerToAddressError(tok->next());
else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare())

View File

@ -39,6 +39,7 @@ private:
TEST_CASE(functionpar);
TEST_CASE(structmember);
TEST_CASE(ptrcompare);
TEST_CASE(ptrarithmetic);
}
void check(const char code[])
@ -118,6 +119,28 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
void ptrarithmetic()
{
// #3073
check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = p + x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x + p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(int *p) {\n"
" int x = 10;\n"
" int *a = x * x;\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout.str());
}
};
REGISTER_TEST(Test64BitPortability)