Fixed #3073 (False positive: Assigning an integer (int/long/etc) to a pointer is not portable)
This commit is contained in:
parent
85d83d86ac
commit
c34b77cebf
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue