Browse Source

AP_HAL_SITL: Protect against nullpointer dereference

mission-4.1.18
Michael du Breuil 7 years ago committed by Randy Mackay
parent
commit
5bd4091976
  1. 11
      libraries/AP_HAL_SITL/SITL_State.cpp

11
libraries/AP_HAL_SITL/SITL_State.cpp

@ -492,8 +492,9 @@ void SITL_State::set_height_agl(void) @@ -492,8 +492,9 @@ void SITL_State::set_height_agl(void)
}
#if AP_TERRAIN_AVAILABLE
if (_terrain &&
_sitl->terrain_enable) {
if (_terrain != nullptr &&
_sitl != nullptr &&
_sitl->terrain_enable) {
// get height above terrain from AP_Terrain. This assumes
// AP_Terrain is working
float terrain_height_amsl;
@ -508,8 +509,10 @@ void SITL_State::set_height_agl(void) @@ -508,8 +509,10 @@ void SITL_State::set_height_agl(void)
}
#endif
// fall back to flat earth model
_sitl->height_agl = _sitl->state.altitude - home_alt;
if (_sitl != nullptr) {
// fall back to flat earth model
_sitl->height_agl = _sitl->state.altitude - home_alt;
}
}
#endif

Loading…
Cancel
Save