Skip to content

Fix false positive AssignmentIntegerToAddress#2971

Merged
danmar merged 2 commits into
cppcheck-opensource:mainfrom
Ken-Patrick:AssignmentIntegerToAddress
Dec 24, 2020
Merged

Fix false positive AssignmentIntegerToAddress#2971
danmar merged 2 commits into
cppcheck-opensource:mainfrom
Ken-Patrick:AssignmentIntegerToAddress

Conversation

@Ken-Patrick
Copy link
Copy Markdown
Contributor

Due to a issue while parsing the function declaration (we ended up with
the type of the first argument instead of the return type).

c.cpp:6:11: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
  Array a = f(i);
          ^

typedef std::array<int, 2> Array;

Array f(int i);

int g(int i) {
Array a = f(i);
return 2;
}

Due to a issue while parsing the function declaration (we ended up with
the type of the first argument instead of the return type).

```
c.cpp:6:11: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
  Array a = f(i);
          ^
```
typedef std::array<int, 2> Array;

Array f(int i);

int g(int i) {
  Array a = f(i);
  return 2;
}
```
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! If you remove the if I pointed out I feel this can be merged.

Comment thread test/testsymboldatabase.cpp Outdated
// 1 scopes: Global
ASSERT(db && db->scopeList.size() == 1);

if (db) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such if was needed until 2-3 years ago. Nowadays an ASSERT will stop the test if the condition is false. So please remove this redundant if.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the opportunity to clean the whole file.

@Ken-Patrick Ken-Patrick force-pushed the AssignmentIntegerToAddress branch from 23e903c to 3ddc36c Compare December 23, 2020 08:42
@Ken-Patrick Ken-Patrick force-pushed the AssignmentIntegerToAddress branch from 3ddc36c to ad74ea2 Compare December 23, 2020 09:28
@danmar danmar merged commit aad723b into cppcheck-opensource:main Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants