diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 22fa92f..39c0601 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -981,8 +981,10 @@ uint16_t QuectelRadio::getQuectelChecksum(const void* data, size_t nBytes) { for (size_t i = 0; i < nBytes; i += 2) { // If the number of the characters is odd, set the last character as the high 8 bit, and the low 8 bit as 0, // and then use an XOR operator to calculate the checksum. + bool bHasLowByte = (i + 1 < nBytes); + uint8_t high = castData[i]; - uint8_t low = (i < nBytes) ? (castData[i+1]) : (0); + uint8_t low = bHasLowByte ? (castData[i+1]) : (0); uint16_t iFragment = bytesToUint16(high, low); updateQuectelChecksum(iChecksum, iFragment); |