1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 10:33:29 -05:00

AIS: NMEA sentences must end with CR/LF. Don't read beyond end of array.

This commit is contained in:
Jon Beniston 2022-07-17 13:15:17 +01:00
parent dcd0ee2272
commit 4ac05f427f

View File

@ -60,7 +60,11 @@ QString AISMessage::toNMEA(const QByteArray bytes)
int c = 0; int c = 0;
for (int j = 0; j < 6; j++) for (int j = 0; j < 6; j++)
{ {
c = (c << 1) | ((bytes[i] >> (bits - 1)) & 0x1); if (i < bytes.size()) {
c = (c << 1) | ((bytes[i] >> (bits - 1)) & 0x1);
} else {
c = (c << 1);
}
bits--; bits--;
if (bits == 0) if (bits == 0)
{ {
@ -92,7 +96,7 @@ QString AISMessage::toNMEA(const QByteArray bytes)
sentence++; sentence++;
} }
return nmeaSentences.join("\n"); return nmeaSentences.join("\r\n").append("\r\n"); // NMEA-0183 requires CR and LF
} }
QString AISMessage::toNMEA() QString AISMessage::toNMEA()