1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-08-12 22:43:36 -04:00

Fix undefined left shift in SimpleDeserializer::readS64

The signed 64-bit deserialization code used a signed temporary value while
assembling bytes:

    tmp = (tmp << 8) | byte;

For negative values, tmp was initialized to -1 for sign extension. Left-shifting
this negative value is undefined behavior in C++.

Use an unsigned temporary while constructing the 64-bit representation and
convert to qint64 after all bytes have been assembled. This preserves the
existing two's complement sign handling while avoiding undefined behavior.

Fixes static analysis warning about shifting a negative value.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
This commit is contained in:
Robin Getz
2026-08-01 15:10:48 -04:00
parent 742746dc7b
commit 1330a0639d
+3 -3
View File
@@ -392,7 +392,7 @@ returnDefault:
bool SimpleDeserializer::readS64(quint32 id, qint64* result, qint64 def) const
{
uint readOfs;
qint64 tmp;
quint64 tmp;
Elements::const_iterator it = m_elements.constFind(id);
if(it == m_elements.constEnd())
goto returnDefault;
@@ -406,10 +406,10 @@ bool SimpleDeserializer::readS64(quint32 id, qint64* result, qint64 def) const
for(uint i = 0; i < it->length; i++) {
quint8 byte = readByte(&readOfs);
if((i == 0) && (byte & 0x80))
tmp = -1;
tmp = 0xFFFFFFFFFFFFFFFFULL;
tmp = (tmp << 8) | byte;
}
*result = tmp;
*result = static_cast<qint64>(tmp);
return true;
returnDefault: