MTP: Compatibility fixes for transferring strings

Change-Id: Ic06d754ee68b0389439cdc34f73adff0f2b33afa
Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood
2010-08-18 12:31:09 -04:00
parent 243efd2c57
commit 9e837861b2
3 changed files with 9 additions and 3 deletions

View File

@@ -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

View File

@@ -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); }

View File

@@ -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