diff --git a/common/commonutil.c b/common/commonutil.c index 4af16b3c0..5bb77a936 100644 --- a/common/commonutil.c +++ b/common/commonutil.c @@ -161,27 +161,39 @@ uint64_t bytes_to_num(uint8_t *src, size_t len) { } uint16_t MemLeToUint2byte(const uint8_t *data) { - return (data[1] << 8) + data[0]; + return (uint16_t)( + (data[1] << 8) + data[0] + ); } uint32_t MemLeToUint3byte(const uint8_t *data) { - return (data[2] << 16) + (data[1] << 8) + data[0]; + return (uint32_t)( + (data[2] << 16) + (data[1] << 8) + data[0] + ); } uint32_t MemLeToUint4byte(const uint8_t *data) { - return (data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0]; + return (uint32_t)( + (data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0] + ); } uint16_t MemBeToUint2byte(const uint8_t *data) { - return (data[0] << 8) + data[1]; + return (uint16_t)( + (data[0] << 8) + data[1] + ); } uint32_t MemBeToUint3byte(const uint8_t *data) { - return (data[0] << 16) + (data[1] << 8) + data[2]; + return (uint32_t)( + (data[0] << 16) + (data[1] << 8) + data[2] + ); } uint32_t MemBeToUint4byte(const uint8_t *data) { - return (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]; + return (uint32_t)( + (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3] + ); } void Uint2byteToMemLe(uint8_t *data, uint16_t value) {