Skip to content

Fix #5115 (False positive: redundantAssignment when using a union) #6484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 7, 2024

Conversation

olabetskyi
Copy link
Collaborator

No description provided.

@danmar danmar changed the title Fix #5115: redundantAssignment when using a union Fix #5115 (False positive: redundantAssignment when using a union) Jun 4, 2024
Copy link
Owner

@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.

might be a working approach.

@danmar
Copy link
Owner

danmar commented Jun 4, 2024

will we still warn about some redundant assignments properly? maybe you could add a test case where the read is removed.

I would prioritize that we don't write false positives. but if we don't have false negatives that is nice.

@chrchr-github
Copy link
Collaborator

Does this also fix https://trac.cppcheck.net/ticket/10093?

@olabetskyi
Copy link
Collaborator Author

It's suppose to I will add the test for it as well when I finished fixing false negatives

@olabetskyi olabetskyi merged commit f1ddd1a into danmar:main Jun 7, 2024
63 checks passed
@mptre
Copy link
Contributor

mptre commented Jun 8, 2024

This change seem to have introduced a regression.

$ cat fp.c
void
fp(char *ptr)
{
        union {
                char *s8;
                unsigned long long u64;
        } addr;
        addr.s8 = ptr;
        addr.u64 += 8;
}
$ cppcheck --enable-all fp.c
Checking union.c ...
union.c:9:11: style: Variable 'addr.s8' is reassigned a value before the old one has been used. [redundantAssignment]
 addr.u64 += 8;
          ^
union.c:8:10: note: addr.s8 is assigned
 addr.s8 = ptr;
         ^
union.c:9:11: note: addr.s8 is overwritten
 addr.u64 += 8;
          ^

@olabetskyi
Copy link
Collaborator Author

A small fix will solve it. I will push it

@olabetskyi olabetskyi deleted the union branch June 10, 2024 08:03
@olabetskyi
Copy link
Collaborator Author

d33d29c fix

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.

4 participants