Skip to content

Fix potential null indirections#774

Open
tadhunt wants to merge 1 commit intogarbagemule:masterfrom
tadhunt:null-pointer-access-cleanup
Open

Fix potential null indirections#774
tadhunt wants to merge 1 commit intogarbagemule:masterfrom
tadhunt:null-pointer-access-cleanup

Conversation

@tadhunt
Copy link
Contributor

@tadhunt tadhunt commented Sep 19, 2023

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Documentation
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

Problem

Fix code paths that might result in null indirections

  • GitHub issue (optional):

Solution

Action

@tadhunt tadhunt changed the title Fix possible null indirection warnings Fix potential null indirections Sep 19, 2023
Copy link
Owner

@garbagemule garbagemule left a comment

Choose a reason for hiding this comment

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

As much as I'd like to silence the ArenaRegion warning, I don't like the idea of introducing a "no-op null check", because it could just make the code that more confusing ("why is there a null check here, when it doesn't seem to ever be the case?"). A complete refactoring of the region class is a pretty big ask, though, and definitely not an adventure I expect anyone to embark on 😛

I think without the ArenaRegion change, the WaveParser change would probably fit better in the warning cleanup PR along with the other default branch changes.

Comment on lines -527 to +528
if (lower != null) setLocation(coords, r1.name().toLowerCase(), lower);
if (upper != null) setLocation(coords, r2.name().toLowerCase(), upper);
if (lower != null && r1 != null) setLocation(coords, r1.name().toLowerCase(), lower);
if (upper != null && r2 != null) setLocation(coords, r2.name().toLowerCase(), upper);
Copy link
Owner

Choose a reason for hiding this comment

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

It took me a while to figure out what the heck the code in this method actually does; it's a bit messy to say the least...

This change is not actually necessary, because in all the branches of the switch statement, both r1 and r2 are assigned values. Except for the default branch, of course, which also assigns null to both upper and lower, which means the "transitive null checks" are sufficient. Also, the default branch can't be reached in the current state of the code base, because the only values ever given as RegionPoint are the ones in the four branches.

I can't really tell if it's worth making this code change in order to silence a warning. The underlying issue is that the code is much too messy, I think, so perhaps it would be better with a small refactoring of the method or the class in its entirety?

Comment on lines +101 to +102
default:
throw new ConfigError("Unknown wave type for wave " + name + " of arena " + arena.configName() + ": " + t);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure why there is a warning about a default branch here, since the current branches are exhaustive. I guess it can't hurt to have it in case a new wave type is introduced, though.

@tadhunt
Copy link
Contributor Author

tadhunt commented Oct 21, 2023

Regarding refactoring, I can't commit to that as I don't really understand this code and am worried about breaking it in some non-obvious way.

Re: requests above, I didn't see anything directly actionable from your notes. Did you have something specific I should change?

Maybe we just add a comment to the changes in this PR that notes this needs a major refactoring?

@garbagemule
Copy link
Owner

Regarding refactoring, I can't commit to that as I don't really understand this code and am worried about breaking it in some non-obvious way.

For sure. Unless you have an irrational desire to refactor moldy spaghetti code that takes several passes just to kinda understand the overall idea of, this isn't something I'd realistically expect anyone to do, so no worries 😛

Re: requests above, I didn't see anything directly actionable from your notes. Did you have something specific I should change?

Maybe we just add a comment to the changes in this PR that notes this needs a major refactoring?

I think the most consistent thing to do here would be to close this PR, but move the change with the default branch in WaveParser over to the commit in #773 that already deals with fixing switch statements, since it fits really nicely in there. I'm more than happy to assist with wrangling git 😃

@tadhunt
Copy link
Contributor Author

tadhunt commented Oct 22, 2023

SGTM!

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.

2 participants