1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-08-10 21:43:31 -04:00

modais: Initialize output bytes before HDLC bit packing

The HDLC encoder accumulated bits into m_bits using the |= operator
without first initializing the first byte. This resulted in an
uninitialized read of m_bits[0] when encoding the first bit of a
packet.

Initialize each output byte when writing its first bit, ensuring the
buffer contains a defined value before bits are OR'ed into it. This
also makes addBit() self-contained, eliminating the need for callers to
pre-initialize the current output byte.

Reported by Coverity.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
This commit is contained in:
Robin Getz
2026-08-02 18:53:58 -04:00
parent 862e838b65
commit ee24189bd2
@@ -412,6 +412,9 @@ int AISModSource::getBit()
void AISModSource::addBit(int bit)
{
if (m_bitIdx == 0)
m_bits[m_byteIdx] = 0;
// Transmit LSB first
m_bits[m_byteIdx] |= bit << m_bitIdx;
m_bitIdx++;