AP_HAL_SITL: Protect against nullpointer dereference

This commit is contained in:
Michael du Breuil 2018-03-30 22:11:31 -07:00 committed by Randy Mackay
parent c627ed6ae3
commit 5bd4091976

View File

@ -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)
}
#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