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

Remove null pointer checks when the pointer had already been used. Th… #7852

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

Dave-Lowndes
Copy link
Contributor

Remove null pointer checks when the pointer had already been used. The code would have caused a crash before the null pointer test if it'd ever occur, so presumably it doesn't.

…e code would have caused a crash before the null pointer test if it'd ever occur, so presumably it doesn't.
@baconpaul
Copy link
Collaborator

I want to peek at each of these in a touch more detail I merge on this one.

thanks for all of these!

if you would like I would love to see what you find when you run across the shortcircuit-xt codebase we have here too!

@Dave-Lowndes
Copy link
Contributor Author

@baconpaul I've had a brief look at the shortcircuit-xt code and have added comments/issues to a couple. Many of the reported issues are common with this codebase, so it's currently difficult to see the wood for the trees.

@baconpaul
Copy link
Collaborator

Great.
My week became a bit complicated but I have some dev time this afternoon/evening and all your PRs are top of my list.

Is there a sort of 'raw dumped output' from the tool as a massive text file we could have on scxt? or does it not work that way.

These are super useful!

@Dave-Lowndes
Copy link
Contributor Author

@baconpaul It can save its log in a variety of formats (txt, csv, html, json) but I only ever use it interactively from the VS IDE so I'm not sure how easy it is to work with them. It's best to have static analysis always on the go to keep on top of any issues, otherwise it's an enormous task to manage.
Would you like me to save a particular format file somewhere after this set of updates are made?

@baconpaul
Copy link
Collaborator

yeah i wonder if the tool integrates with clion yet.

I'd be happy to look at an html doc or whatever though to get an idea of the sort of things it is showing!

I merged a few other of your changes already this morning by the wya.

@Dave-Lowndes
Copy link
Contributor Author

Yes, it appears that you can use it from CLion https://pvs-studio.com/en/docs/manual/0052/
How can I send you a file output, I'm not familiar with what scxt may be!

@mkruselj
Copy link
Collaborator

SCXT is just a shorthand for the other repo, Shortcircuit XT.

@@ -839,7 +839,6 @@ CREATE TABLE IF NOT EXISTS Favorites (
std::ostringstream searchName;
searchName << p.name << " ";

if (storage)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The static analyzer is sort of correct here, that storage is used above, but it is only used in an exception path. The correct fix I think is not to remove this guard, but to guard the report errors above. I'll make that change on the branch.

Copy link
Contributor Author

@Dave-Lowndes Dave-Lowndes Nov 21, 2024

Choose a reason for hiding this comment

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

@baconpaul IIRC there are many places where it's used unguarded and I couldn't think why it should only not be null only in exception paths - which was why I assumed it probably never is null in practice!
Looking again, the constructor of WriterWorker would crash if it was passed a nullptr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this function it's only used prior in the exception path. so i flipped it to check the exception paths

Those exceptions are pretty rare so I think if storage was null those cases would crash.

I sort of wish there was an easy non-nullable pointer type. I guess that's a & but they are clumsy to mutate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constructor on L413 would crash were it ever passed a nullptr for storage.
Reworking using a ref for storage seems to build fine for me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah i think you are correct.

Since synth : storage : ui are all 1:1 in surge right now, we really should have set everything up as a & or const&. That's more what we are doing in short circuit. Many of the 2004 bones are still on display in the raw pointer idiom here.

@baconpaul baconpaul merged commit ad9d5f3 into surge-synthesizer:main Nov 22, 2024
13 checks passed
@Dave-Lowndes Dave-Lowndes deleted the PointerChecksAfterUse branch November 22, 2024 15:03
@Dave-Lowndes
Copy link
Contributor Author

@baconpaul
Can you tell me the best place to save a CSV dump of the analysis warnings?
Should I create an issue and add it there, or something else?

@baconpaul
Copy link
Collaborator

Oh yeah that would be perfect. Just attach a CSV dump to an issue as a zip file.

I keep meaning to get around to applying for an open source license for the tool but just been a really nutty winter.

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