File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ void Check64BitPortability::pointerassignment()
5858 const Variable *var1 (symbolDatabase->getVariableFromVarId (tok->tokAt (1 )->varId ()));
5959 const Variable *var2 (symbolDatabase->getVariableFromVarId (tok->tokAt (3 )->varId ()));
6060
61- if (isaddr (var1) && isint (var2))
61+ if (isaddr (var1) && isint (var2) && tok-> strAt ( 4 ) != " + " )
6262 assignmentIntegerToAddressError (tok->next ());
6363
6464 else if (isint (var1) && isaddr (var2) && !tok->tokAt (3 )->isPointerCompare ())
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ class Test64BitPortability : public TestFixture
3939 TEST_CASE (functionpar);
4040 TEST_CASE (structmember);
4141 TEST_CASE (ptrcompare);
42+ TEST_CASE (ptrarithmetic);
4243 }
4344
4445 void check (const char code[])
@@ -118,6 +119,28 @@ class Test64BitPortability : public TestFixture
118119 " }\n " );
119120 ASSERT_EQUALS (" " , errout.str ());
120121 }
122+
123+ void ptrarithmetic ()
124+ {
125+ // #3073
126+ check (" void foo(int *p) {\n "
127+ " int x = 10;\n "
128+ " int *a = p + x;\n "
129+ " }\n " );
130+ ASSERT_EQUALS (" " , errout.str ());
131+
132+ check (" void foo(int *p) {\n "
133+ " int x = 10;\n "
134+ " int *a = x + p;\n "
135+ " }\n " );
136+ ASSERT_EQUALS (" " , errout.str ());
137+
138+ check (" void foo(int *p) {\n "
139+ " int x = 10;\n "
140+ " int *a = x * x;\n "
141+ " }\n " );
142+ TODO_ASSERT_EQUALS (" error" , " " , errout.str ());
143+ }
121144};
122145
123146REGISTER_TEST (Test64BitPortability)
You can’t perform that action at this time.
0 commit comments