mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Decoder: 64-bit shift to avoid UB
Shifting a value by more than the size of its type is UB. This was actually causing mangled serial numbers with optimization on using Clang 12 on Linux.
This commit is contained in:
@@ -13,10 +13,10 @@
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
uint64_t Decoder::GetUInt64FromLEBytes(uint8_t* bytes) {
|
||||
uint64_t Decoder::GetUInt64FromLEBytes(const uint8_t* bytes) {
|
||||
uint64_t ret = 0;
|
||||
for(int i = 0; i < 8; i++)
|
||||
ret |= (bytes[i] << (i * 8));
|
||||
ret |= (uint64_t(bytes[i]) << (i * 8));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace icsneo {
|
||||
|
||||
class Decoder {
|
||||
public:
|
||||
static uint64_t GetUInt64FromLEBytes(uint8_t* bytes);
|
||||
static uint64_t GetUInt64FromLEBytes(const uint8_t* bytes);
|
||||
|
||||
Decoder(device_eventhandler_t report) : report(report) {}
|
||||
bool decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet);
|
||||
|
||||
Reference in New Issue
Block a user