From 8afe4f4a1f1450ddc6b1964dc4e5cff598160d7e Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Sat, 6 Nov 2021 12:09:52 -0400 Subject: [PATCH] Fix NXDN transmit issue and android USB device buffer overflow crash bug --- android/AndroidManifest.xml | 100 ++++++++++++++++++------------------ androidserialport.cpp | 2 + nxdncodec.cpp | 9 ++-- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 90948ef..e17979d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,6 +1,6 @@ - + @@ -13,71 +13,71 @@ - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - + + + + + - - - - - + + + + + diff --git a/androidserialport.cpp b/androidserialport.cpp index e7e2654..2cedc77 100644 --- a/androidserialport.cpp +++ b/androidserialport.cpp @@ -64,6 +64,7 @@ int AndroidSerialPort::write(char *data, int s) jbyteArray buffer = env->NewByteArray(s); env->SetByteArrayRegion(buffer, 0, s, (jbyte *)data); serialJavaObject.callMethod("write", "([B)V", buffer); + env->DeleteLocalRef(buffer); return 0; } @@ -73,6 +74,7 @@ int AndroidSerialPort::write(QByteArray data) jbyteArray buffer = env->NewByteArray(data.size()); env->SetByteArrayRegion(buffer, 0, data.size(), (jbyte *)data.data()); serialJavaObject.callMethod("write", "([B)V", buffer); + env->DeleteLocalRef(buffer); return 0; } diff --git a/nxdncodec.cpp b/nxdncodec.cpp index 18a2f90..26f494a 100755 --- a/nxdncodec.cpp +++ b/nxdncodec.cpp @@ -282,7 +282,6 @@ void NXDNCodec::send_disconnect() void NXDNCodec::transmit() { - uint8_t ambe_frame[49]; uint8_t ambe[7]; int16_t pcm[160]; @@ -314,13 +313,11 @@ void NXDNCodec::transmit() } else{ if(m_modeinfo.sw_vocoder_loaded){ - m_mbevocoder->encode_2450(pcm, ambe_frame); + m_mbevocoder->encode_2450(pcm, ambe); } + ambe[6] &= 0x80; + for(int i = 0; i < 7; ++i){ - for(int j = 0; j < 8; ++j){ - ambe[i] |= (ambe_frame[(i*8)+j] << (7-j)); - } - ambe[6] &= 0x80; m_txcodecq.append(ambe[i]); } }