MTP: Compatibility fixes for transferring strings
Change-Id: Ic06d754ee68b0389439cdc34f73adff0f2b33afa
Signed-off-by: Mike Lockwood <lockwood@android.com>
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::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 @@
}
packet->putUInt16(ch);
}
+ // only terminate with zero if string is not empty
+ if (count > 0)
+ packet->putUInt16(0);
}
} // namespace android