diff options
-rw-r--r-- | media/mtp/MtpDataPacket.cpp | 5 | ||||
-rw-r--r-- | media/mtp/MtpDataPacket.h | 2 | ||||
-rw-r--r-- | media/mtp/MtpStringBuffer.cpp | 5 |
3 files changed, 9 insertions, 3 deletions
diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp index 9bfd00f..27dc796 100644 --- a/media/mtp/MtpDataPacket.cpp +++ b/media/mtp/MtpDataPacket.cpp @@ -325,9 +325,12 @@ void MtpDataPacket::putString(const uint16_t* string) { else break; } - putUInt8(count); + putUInt8(count > 0 ? count + 1 : 0); for (int i = 0; i < count; i++) putUInt16(string[i]); + // only terminate with zero if string is not empty + if (count > 0) + putUInt16(0); } #ifdef MTP_DEVICE diff --git a/media/mtp/MtpDataPacket.h b/media/mtp/MtpDataPacket.h index b458286..1467aab 100644 --- a/media/mtp/MtpDataPacket.h +++ b/media/mtp/MtpDataPacket.h @@ -83,7 +83,7 @@ public: void putString(const MtpStringBuffer& string); void putString(const char* string); void putString(const uint16_t* string); - inline void putEmptyString() { putUInt16(0); } + inline void putEmptyString() { putUInt8(0); } inline void putEmptyArray() { putUInt32(0); } diff --git a/media/mtp/MtpStringBuffer.cpp b/media/mtp/MtpStringBuffer.cpp index 2d3cf69..8bf6731 100644 --- a/media/mtp/MtpStringBuffer.cpp +++ b/media/mtp/MtpStringBuffer.cpp @@ -112,7 +112,7 @@ void MtpStringBuffer::readFromPacket(MtpDataPacket* packet) { void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const { int count = mCharCount; const uint8_t* src = mBuffer; - packet->putUInt8(count); + packet->putUInt8(count > 0 ? count + 1 : 0); // expand utf8 to 16 bit chars for (int i = 0; i < count; i++) { @@ -133,6 +133,9 @@ void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const { } packet->putUInt16(ch); } + // only terminate with zero if string is not empty + if (count > 0) + packet->putUInt16(0); } } // namespace android |