Browse Source

modemdab: Avoid Coverity overflow warning in CRC16

Fix Coverity CID 657927 by explicitly limiting the complemented
CRC to 16 bits using XOR with 0xffff. This avoids the reported
overflow when returning the complemented value as uint16_t.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.1.0
Robin Getz 4 weeks ago
parent
commit
68585cac68
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 2
      modemdab/dabtables.cpp

2
modemdab/dabtables.cpp

@ -446,7 +446,7 @@ uint16_t DABTables::crc16(const uint8_t *data, std::size_t length) @@ -446,7 +446,7 @@ uint16_t DABTables::crc16(const uint8_t *data, std::size_t length)
crc = (crc & 0x8000) ? static_cast<uint16_t>((crc << 1) ^ 0x1021) : static_cast<uint16_t>(crc << 1);
}
}
return static_cast<uint16_t>(~crc);
return static_cast<uint16_t>(~crc ^ 0xffff);
}
bool DABTables::crc16Check(const uint8_t *data, std::size_t lengthWithCRC)

Loading…
Cancel
Save