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

View File

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