Skip to content
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

updated Cppcheck to 2.12.1 / provide more includes to Cppcheck #2785

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

firewave
Copy link
Contributor

@firewave firewave commented Sep 4, 2023

Cppcheck is by design lenient with incorrect and incomplete code. This allows code to be scanned more easily but without all the code provided it might not be possible to detect certain issues. An indicator for this is the missingInclude warning.

This provides the most common missing headers to the analysis and fixes the additionally detected issues. Unfortunately it causes the time of the analysis to balloon but that is expected.

@firewave
Copy link
Contributor Author

firewave commented Sep 4, 2023

There's several more includes to add but I wanted to keep it to the basics first.

I still have to look into the shiftTooManyBits warnings - it is possible these might be false positives.

And I will prepare an upstream PR for the warnings in ulalaca - if necessary.

@matt335672
Copy link
Member

Thanks @firewave

A couple of initial comments. This isn't a full review, but I like what you're doing here.

  • Increase in time is fine. We're using C, so a more detailed static analysis is always welcome.
  • Suggest you add an ignore for ulalaca for now. @unstabler - is this OK with you?

@firewave
Copy link
Contributor Author

firewave commented Sep 4, 2023

  • Increase in time is fine. We're using C, so a more detailed static analysis is always welcome.

It is a bit steep though. I will take a look into it. Maybe there is something to improve upstream.

  • Suggest you add an ignore for ulalaca for now.

Done. Upstream PR will follow soon.

@firewave
Copy link
Contributor Author

firewave commented Sep 4, 2023

The shiftTooManyBits appears to be a false positive. I filed an upstream ticket about it: https://trac.cppcheck.net/ticket/11916 and suppress it for now.

@firewave
Copy link
Contributor Author

firewave commented Sep 4, 2023

This is complete for now. Please have a close look at the nullPointerRedundantCheck fixes.

I will let it soak for a day before I will flag it as ready so I can have a fresh look at it tomorrow.

Copy link
Member

@matt335672 matt335672 left a comment

Choose a reason for hiding this comment

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

A couple of comments. Your changes to the clipboard code look fine to me. There may be some other dragons in this code, but let's not worry about those now.

@@ -45,6 +45,7 @@ if [ -z "$CPPCHECK_FLAGS" ]; then
CPPCHECK_FLAGS="--quiet --force --std=c11 --std=c++11 --inline-suppr \
--enable=warning --error-exitcode=1 -i third_party \
--suppress=uninitMemberVar:ulalaca/ulalaca.cpp \
--suppress=shiftTooManyBits:libxrdp/xrdp_mppc_enc.c \
Copy link
Member

Choose a reason for hiding this comment

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

Personally I'd prefer to add this inline to the code - see (e.g.) sesman/chansrv/chansrv_fuse.c:2779 for an example. Or is there a good reason why it's better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No real reason. Possibly because it is several warnings and I suppressed the other ones like this.

if (cptr == NULL)
{
g_free(g_clip_s2c.data);
g_clip_s2c.data = 0;

/* cannot add any more data */
Copy link
Member

Choose a reason for hiding this comment

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

Move this comment to start of block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@firewave firewave force-pushed the cppcheck-inc branch 2 times, most recently from d970bd2 to 13a6be0 Compare September 9, 2023 17:54
@firewave
Copy link
Contributor Author

firewave commented Sep 9, 2023

To mitigate the performance regression a bit I build Cppcheck with Boost enabled. To make sure it is being rebuild I added -boost to the cache key. That can be removed when you update to the next version. This reduces the runtime from >10 minutes to <7 minutes. It used to be ~1 minute.

There are possible further optimizations like LTO, -O3 or using Clang as compiler as well as PGO/BOLT but most of these have not yet been properly evaluated yet. I will add more information about these to the Cppcheck documentation in the future.

@matt335672
Copy link
Member

That's a worthwhile optimisation.

As it happens cppcheck 2.12.0 has been released today (I've got a watch on the repo for new releases).

I've just run 2.12.0 over the existing devel branch and using the existing scripts no new errors were found. Do you want to add 2.12.0 support in to this PR? We can then merge it in one go.

@firewave
Copy link
Contributor Author

That's a worthwhile optimisation.

I also just realized you are not using the matchcompiler. Will add it as well.

As it happens cppcheck 2.12.0 has been released today (I've got a watch on the repo for new releases).

I've just run 2.12.0 over the existing devel branch and using the existing scripts no new errors were found. Do you want to add 2.12.0 support in to this PR? We can then merge it in one go.

Already done. Unfortunately the performance regressions in 2.12 (caused by more coverage in the analysis) are more than doubling the analysis time...

@firewave
Copy link
Contributor Author

Already done. Unfortunately the performance regressions in 2.12 (caused by more coverage in the analysis) are more than doubling the analysis time...

With the matchcompiled code this drops from > 15 minutes to ~9 Minutes.

@firewave firewave changed the title provide more includes to Cppcheck updated Cppcheck to 2.12.0 / provide more includes to Cppcheck Sep 10, 2023
@matt335672
Copy link
Member

@firewave - this PR is still in draft. Are you proposing to move it out of draft?

PS: cppcheck 2.12.1 has just bee released, but I don't think it's relevant here.

@firewave
Copy link
Contributor Author

@firewave - this PR is still in draft. Are you proposing to move it out of draft?

Sure. I was still waiting for feedback.

Also I saw that you are using merge commits. That would lead to all the individual commits to show up which might not be intended. So far I have mainly worked on projects with "squash merge" and only did the commits so the changes are easier to track. What the desired results of this merge?

PS: cppcheck 2.12.1 has just bee released, but I don't think it's relevant here.

I could update. That would also allow me to drop the -mc suffix on the cache key which I do not want to have in.

@matt335672
Copy link
Member

Well, I'm OK with this so I'd be happy to merge it. I can't do that until it's out of draft.

By all means update to 2.12.1 if that makes things easier.

In terms of commits, are you able to re-arrange to 2 - one for the 2.12.1 update and one for the other changes? If not let me know and we'll work something else out.

@firewave
Copy link
Contributor Author

Well, I'm OK with this so I'd be happy to merge it. I can't do that until it's out of draft.

By all means update to 2.12.1 if that makes things easier.

Not easier but will get rid of a unnecessary nit. Will do.

In terms of commits, are you able to re-arrange to 2 - one for the 2.12.1 update and one for the other changes? If not let me know and we'll work something else out.

Will do as well.

@firewave
Copy link
Contributor Author

Okay - something went wrong with the rebase. Because of the multi-repo stuff my IDE cannot do the Gi>Hub sync/rebase and I have to figure out how to clean this up via the command-line.

@matt335672
Copy link
Member

Let me know if you need a hand to sort it out. I'm a bit busy today in the real world, but I should have some time tomorrow.

- added (temporary) suppression of Cppcheck `shiftTooManyBits` false positives in `libxrdp/xrdp_mppc_enc.c`
- added (temporary) suppression of Cppcheck `uninitMemberVar` true positives in `ulalaca/ulalaca.cpp` until fixes land downstream
- fix Cppcheck `nullPointerRedundantCheck` in `sesman/chansrv/clipboard.c`
- fix Cppcheck `syntaxError` in `fontutils/mkfv1.c` because it doesn't see the `freetype/fterrors.h` header / removed astyle workaround
- build Cppcheck with matchcompiler for improved performance
- build Cppcheck with Boost for improved ValueFlow performance
@firewave firewave changed the title updated Cppcheck to 2.12.0 / provide more includes to Cppcheck updated Cppcheck to 2.12.1 / provide more includes to Cppcheck Oct 17, 2023
@firewave
Copy link
Contributor Author

Let me know if you need a hand to sort it out. I'm a bit busy today in the real world, but I should have some time tomorrow.

Thanks. Turns out I just had to rebase against upstream.

@firewave firewave marked this pull request as ready for review October 17, 2023 13:37
@matt335672 matt335672 merged commit da8fa05 into neutrinolabs:devel Oct 18, 2023
13 checks passed
@matt335672
Copy link
Member

@firewave - thanks for your contribution!

@matt335672
Copy link
Member

@metalefty - do you want this backported to v0.9?

@firewave firewave deleted the cppcheck-inc branch October 18, 2023 08:37
@metalefty
Copy link
Member

Yes, let's ship it.

@matt335672
Copy link
Member

Done.

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.

3 participants