Page MenuHomeWildfire Games

Silence uninitialized variable warnings on MakeGoalReachable and FindNearestNavcellInRegions in rP22817
ClosedPublic

Authored by wraitii on Sep 2 2019, 8:03 PM.

Details

Summary

Silence VS15 / gcc warnings on rP22817

Test Plan

Compile with VS15 or gcc and report that the warnings are gone

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.Sep 2 2019, 8:03 PM
Vulcan added a comment.Sep 2 2019, 8:07 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/52/display/redirect

Vulcan added a comment.Sep 2 2019, 8:17 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/561/display/redirect

elexis added a subscriber: elexis.Sep 2 2019, 10:28 PM

The warnings also appear with gcc in fact:

../../../source/simulation2/helpers/HierarchicalPathfinder.cpp: In member function ‘void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set<HierarchicalPathfinder::RegionID, HierarchicalPathfinder::SortByCenterToPoint>&, u16&, u16&, pass_class_t) const’:
../../../source/simulation2/helpers/HierarchicalPathfinder.cpp:747:8: warning: ‘bestJ’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  747 |  jGoal = bestJ;
      |  ~~~~~~^~~~~~~
../../../source/simulation2/helpers/HierarchicalPathfinder.cpp:746:8: warning: ‘bestI’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  746 |  iGoal = bestI;
      |  ~~~~~~^~~~~~~

I didn't verify if they are always overwritten otherwise, otherwise thanks for the fix.

elexis retitled this revision from Silence VS15 warnings on rP22817 to Silence uninitialized variable warnings on MakeGoalReachable and FindNearestNavcellInRegions in rP22817.Sep 2 2019, 10:35 PM
elexis edited the summary of this revision. (Show Details)
elexis edited the test plan for this revision. (Show Details)
wraitii updated this revision to Diff 9649.Sep 7 2019, 10:47 AM

I guess these could indeed be undefined if regions is empty, and that doesn't necessarily sounds like an unrecoverable error, so clarify the comment.

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/87/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/596/display/redirect

Somewhat sensible default-values

Somewhat sounds like partial. Is there a case where the return value is wrong if empty regions are passed? Like there not being a navcell at the target?
Should there be an early return, perhaps false returned on failure bool on success, or an ENSURE if it should never happen (not even in test setups or the extreme maps)?

In D2250#94153, @elexis wrote:

Somewhat sounds like partial. Is there a case where the return value is wrong if empty regions are passed? Like there not being a navcell at the target?
Should there be an early return, perhaps false returned on failure bool on success, or an ENSURE if it should never happen (not even in test setups or the extreme maps)?

It does sound like we could do something else... But I don't think we can. The two callers of FindNearestNavcellInRegions are MakeGoalReachable and FindNearestPassableNavcell. In both cases, if we have no eligible navels whatsoever (aka the whole map is impassable), then the most sensible thing to do is either crash or do nothing (since the map doesn't make sense anyways). By doing nothing, this behaves exactly as if the whole map was passable then, which sounds fair enough to me.

Reporting the failure doesn't do much good, since there's no way to really recover from that. At the same time it doesn't sound like a crash-worthy offence to me.

I could report a warning, but I'm not sure it'd do much good.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 9 2019, 8:57 PM
This revision was automatically updated to reflect the committed changes.