From 9355444f077e2d35a614663901ebe5ca2b154b66 Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Fri, 8 Mar 2019 19:40:21 +0100 Subject: [PATCH] Fix get_32bit_val call --- Firmware/communication/can_simple.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Firmware/communication/can_simple.cpp b/Firmware/communication/can_simple.cpp index 68bc1ae7..f716cc72 100644 --- a/Firmware/communication/can_simple.cpp +++ b/Firmware/communication/can_simple.cpp @@ -374,11 +374,17 @@ uint8_t CANSimple::get_cmd_id(uint32_t msgID) { } int16_t CANSimple::get_16bit_val(CAN_message_t& msg, uint8_t start_byte) { - return msg.buf[start_byte] + (msg.buf[start_byte + 1] << 8); + int16_t retVal = 0; + if(msg.len - start_byte >= sizeof(retVal)) + retVal = std::memcpy(&retVal, &(msg.buf[start_byte]), sizeof(retVal)); + return retVal; } int32_t CANSimple::get_32bit_val(CAN_message_t& msg, uint8_t start_byte) { - return get_16bit_val(msg, start_byte) + (get_16bit_val(msg, start_byte + 2) << 16); + int32_t retVal = 0; + if(msg.len - start_byte >= sizeof(retVal)) + std::memcpy(&retVal, &(msg.buf[start_byte]), sizeof(retVal)); + return retVal; } float CANSimple::get_float(CAN_message_t& msg, uint8_t start_byte) {