open-space-collective / open-space-toolkit-physics

Physical units, time, reference frames, environment modeling.
https://open-space-collective.github.io/open-space-toolkit-physics/
Apache License 2.0
25 stars 7 forks source link

fix: change error condition that tried to reference a function from a null pointer #262

Closed kyle-cochran closed 3 months ago

kyle-cochran commented 3 months ago

Fixes a small potential undefined behavior that I saw the compiler complaining about:

/app/src/OpenSpaceToolkit/Physics/Coordinate/Axes.cpp:108:59: warning: 'this' pointer is null [-Wnonnull]
  108 |     if ((aFrameSPtr == nullptr) && (!aFrameSPtr->isDefined()))
      |                                      ~~~~~~~~~~~~~~~~~~~~~^~
In file included from /app/src/OpenSpaceToolkit/Physics/Coordinate/Axes.cpp:7:
/app/include/OpenSpaceToolkit/Physics/Coordinate/Frame.hpp:63:10: note: in a call to non-static member function 'bool ostk::physics::coordinate::Frame::isDefined() const'
   63 |     bool isDefined() const;
      |          ^~~~~~~~~

If the second part of the && were ever reached, we would get undefined behavior and likely a crash. Not a huge deal since the code is about to throw an error anyway, but would probably be confusing.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.24%. Comparing base (b322354) to head (e23f0ac).

Files Patch % Lines
src/OpenSpaceToolkit/Physics/Coordinate/Axes.cpp 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #262 +/- ## ======================================= Coverage 81.24% 81.24% ======================================= Files 97 97 Lines 7982 7982 ======================================= Hits 6485 6485 Misses 1497 1497 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.