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.pull/32/head
parent
09a02ff420
commit
4d655da69d
|
|
@ -13,10 +13,10 @@
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
uint64_t Decoder::GetUInt64FromLEBytes(uint8_t* bytes) {
|
uint64_t Decoder::GetUInt64FromLEBytes(const uint8_t* bytes) {
|
||||||
uint64_t ret = 0;
|
uint64_t ret = 0;
|
||||||
for(int i = 0; i < 8; i++)
|
for(int i = 0; i < 8; i++)
|
||||||
ret |= (bytes[i] << (i * 8));
|
ret |= (uint64_t(bytes[i]) << (i * 8));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace icsneo {
|
||||||
|
|
||||||
class Decoder {
|
class Decoder {
|
||||||
public:
|
public:
|
||||||
static uint64_t GetUInt64FromLEBytes(uint8_t* bytes);
|
static uint64_t GetUInt64FromLEBytes(const uint8_t* bytes);
|
||||||
|
|
||||||
Decoder(device_eventhandler_t report) : report(report) {}
|
Decoder(device_eventhandler_t report) : report(report) {}
|
||||||
bool decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet);
|
bool decode(std::shared_ptr<Message>& result, const std::shared_ptr<Packet>& packet);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue