-
Notifications
You must be signed in to change notification settings - Fork 258
Simplify code and avoid dereferencing null pointer #6619
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
Simplify code and avoid dereferencing null pointer #6619
Conversation
| { | ||
| case no_reaction: | ||
| { | ||
| Assert(out != nullptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but this code looks like it requires out to be non-null in all cases (even if the current version references the nullptr first). Maybe require out to be non-null and see if anything breaks?
|
What do you think about this version (review is easier if you hide the white space)? I think this is pretty good, because:
Let's see what the testers say. |
|
This looks more sensible for sure, but we repeatedly check and grab the additional outputs in the loop this way and the inner logic is also mostly duplicated, right? What do you think about something like |
|
I had been thinking about that myself as well but originally decided against it. I changed it to your suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very clean, now. 👍
While looking at #6556 I noticed that the code of the reactive fluid transport model is a bit confusing and in particular would potentially dereference a null pointer (if
outis a null pointer the old line 89 would dereference it).I fixed the null pointer dereference, but I still have an open question about the functionality of the function: In the current implementation this function will not do anything if
outis not provided, even for the options that do not require access toout. This seems counterintuitive to the idea of an optional argument, either we should assert thatoutis always provided (if we only want to compute melt fractions if it exists), or we should support the case to compute melt fractions if possible even ifoutis not provided. Making an argument optional, but then disabling the whole function if it is not provided just seems like an unintuitive middle ground. I am happy to make either change, but am unsure which way is the correct way to go.@danieldouglas92 any thoughts on this?