AP_ExternalAHRS: Switch from type punning to defined behavior

* This was undefined behavior in the C++ standard
* Use the safer options in AP_Common
* Removes a compiler warning

Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
This commit is contained in:
Ryan Friedman 2023-05-20 21:55:42 -06:00 committed by Andrew Tridgell
parent d40b02fbbd
commit d0b8e672c0

View File

@ -575,14 +575,14 @@ float AP_ExternalAHRS_LORD::extract_float(const uint8_t *data, uint8_t offset) c
{
uint32_t tmp = be32toh_ptr(&data[offset]);
return *reinterpret_cast<float*>(&tmp);
return to_float(tmp);
}
double AP_ExternalAHRS_LORD::extract_double(const uint8_t *data, uint8_t offset) const
{
uint64_t tmp = be64toh_ptr(&data[offset]);
return *reinterpret_cast<double*>(&tmp);
return to_double(tmp);
}
#endif // AP_EXTERNAL_AHRS_LORD_ENABLE