diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index 840fd20ca..a72dee915 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -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()) diff --git a/test/test64bit.cpp b/test/test64bit.cpp index 3fd2a9a61..3f329992d 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -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)