Simplify code and avoid dereferencing null pointer#6619
Merged
tjhei merged 3 commits intogeodynamics:mainfrom Jul 28, 2025
Merged
Simplify code and avoid dereferencing null pointer#6619tjhei merged 3 commits intogeodynamics:mainfrom
tjhei merged 3 commits intogeodynamics:mainfrom
Conversation
tjhei
reviewed
Jul 25, 2025
| { | ||
| case no_reaction: | ||
| { | ||
| Assert(out != nullptr, |
Member
There was a problem hiding this comment.
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?
Member
Author
|
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. |
Member
|
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 |
Member
Author
|
I had been thinking about that myself as well but originally decided against it. I changed it to your suggestion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?