diff --git a/libraries/AP_Math/quaternion.cpp b/libraries/AP_Math/quaternion.cpp index c6e9a5d16e..623b48a8b7 100644 --- a/libraries/AP_Math/quaternion.cpp +++ b/libraries/AP_Math/quaternion.cpp @@ -639,6 +639,9 @@ void QuaternionT::normalize(void) q2 *= quatMagInv; q3 *= quatMagInv; q4 *= quatMagInv; + } else { + // The code goes here if the quaternion is [0,0,0,0]. This shouldn't happen. + INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); } } @@ -722,6 +725,12 @@ QuaternionT QuaternionT::operator/(const QuaternionT &v) const const T &quat2 = q3; const T &quat3 = q4; + const T quatMag = length(); + if (is_zero(quatMag)) { + // The code goes here if the quaternion is [0,0,0,0]. This shouldn't happen. + INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); + } + const T rquat0 = v.q1; const T rquat1 = v.q2; const T rquat2 = v.q3;