AP_AHRS: remove use of uninitialised variable

clang told us:

../../libraries/AP_AHRS/AP_AHRS_NavEKF.cpp:695:35: fatal error: variable 'posD' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
This commit is contained in:
Peter Barker 2016-07-20 10:38:26 +10:00 committed by Lucas De Marchi
parent 7be15be185
commit 78fa23440c
1 changed files with 16 additions and 10 deletions

View File

@ -680,11 +680,14 @@ bool AP_AHRS_NavEKF::get_relative_position_NED(Vector3f &vec) const
case EKF_TYPE1: {
Vector2f posNE;
float posD;
bool position_is_valid = (EKF1.getPosNE(posNE) && EKF1.getPosD(posD));
vec.x = posNE.x;
vec.y = posNE.y;
vec.z = posD;
return position_is_valid;
if (EKF1.getPosNE(posNE) && EKF1.getPosD(posD)) {
// position is valid
vec.x = posNE.x;
vec.y = posNE.y;
vec.z = posD;
return true;
}
return false;
}
#endif
@ -692,11 +695,14 @@ bool AP_AHRS_NavEKF::get_relative_position_NED(Vector3f &vec) const
default: {
Vector2f posNE;
float posD;
bool position_is_valid = (EKF2.getPosNE(-1,posNE) && EKF2.getPosD(-1,posD));
vec.x = posNE.x;
vec.y = posNE.y;
vec.z = posD;
return position_is_valid;
if (EKF2.getPosNE(-1,posNE) && EKF2.getPosD(-1,posD)) {
// position is valid
vec.x = posNE.x;
vec.y = posNE.y;
vec.z = posD;
return true;
}
return false;
}
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL