Loading libs/binder/Parcel.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -2223,9 +2223,7 @@ const char* Parcel::readCString() const const char* eos = reinterpret_cast<const char*>(memchr(str, 0, avail)); if (eos) { const size_t len = eos - str; mDataPos += pad_size(len+1); ALOGV("readCString Setting data pos of %p to %zu", this, mDataPos); return str; return static_cast<const char*>(readInplace(len + 1)); } } return nullptr; Loading libs/binder/tests/binderParcelUnitTest.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,38 @@ using android::String8; using android::binder::Status; using android::binder::unique_fd; static void checkCString(const char* str) { for (size_t i = 0; i < 3; i++) { Parcel p; for (size_t j = 0; j < i; j++) p.writeInt32(3); p.writeCString(str); int32_t pos = p.dataPosition(); p.setDataPosition(0); for (size_t j = 0; j < i; j++) p.readInt32(); const char* str2 = p.readCString(); ASSERT_EQ(std::string(str), str2); ASSERT_EQ(pos, p.dataPosition()); } } TEST(Parcel, TestReadCString) { // we should remove the *CString APIs, but testing them until // they are deleted. checkCString(""); checkCString("a"); checkCString("\n"); checkCString("32"); checkCString("321"); checkCString("3210"); checkCString("3210b"); checkCString("123434"); } TEST(Parcel, NonNullTerminatedString8) { String8 kTestString = String8("test-is-good"); Loading Loading
libs/binder/Parcel.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -2223,9 +2223,7 @@ const char* Parcel::readCString() const const char* eos = reinterpret_cast<const char*>(memchr(str, 0, avail)); if (eos) { const size_t len = eos - str; mDataPos += pad_size(len+1); ALOGV("readCString Setting data pos of %p to %zu", this, mDataPos); return str; return static_cast<const char*>(readInplace(len + 1)); } } return nullptr; Loading
libs/binder/tests/binderParcelUnitTest.cpp +32 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,38 @@ using android::String8; using android::binder::Status; using android::binder::unique_fd; static void checkCString(const char* str) { for (size_t i = 0; i < 3; i++) { Parcel p; for (size_t j = 0; j < i; j++) p.writeInt32(3); p.writeCString(str); int32_t pos = p.dataPosition(); p.setDataPosition(0); for (size_t j = 0; j < i; j++) p.readInt32(); const char* str2 = p.readCString(); ASSERT_EQ(std::string(str), str2); ASSERT_EQ(pos, p.dataPosition()); } } TEST(Parcel, TestReadCString) { // we should remove the *CString APIs, but testing them until // they are deleted. checkCString(""); checkCString("a"); checkCString("\n"); checkCString("32"); checkCString("321"); checkCString("3210"); checkCString("3210b"); checkCString("123434"); } TEST(Parcel, NonNullTerminatedString8) { String8 kTestString = String8("test-is-good"); Loading