Skip to content

Commit ba7202c

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "readCString: implemented with readInplace" into main
2 parents 7ff68ce + 75885d9 commit ba7202c

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

libs/binder/Parcel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,9 +2223,7 @@ const char* Parcel::readCString() const
22232223
const char* eos = reinterpret_cast<const char*>(memchr(str, 0, avail));
22242224
if (eos) {
22252225
const size_t len = eos - str;
2226-
mDataPos += pad_size(len+1);
2227-
ALOGV("readCString Setting data pos of %p to %zu", this, mDataPos);
2228-
return str;
2226+
return static_cast<const char*>(readInplace(len + 1));
22292227
}
22302228
}
22312229
return nullptr;

libs/binder/tests/binderParcelUnitTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,38 @@ using android::String8;
3333
using android::binder::Status;
3434
using android::binder::unique_fd;
3535

36+
static void checkCString(const char* str) {
37+
for (size_t i = 0; i < 3; i++) {
38+
Parcel p;
39+
40+
for (size_t j = 0; j < i; j++) p.writeInt32(3);
41+
42+
p.writeCString(str);
43+
int32_t pos = p.dataPosition();
44+
45+
p.setDataPosition(0);
46+
47+
for (size_t j = 0; j < i; j++) p.readInt32();
48+
const char* str2 = p.readCString();
49+
50+
ASSERT_EQ(std::string(str), str2);
51+
ASSERT_EQ(pos, p.dataPosition());
52+
}
53+
}
54+
55+
TEST(Parcel, TestReadCString) {
56+
// we should remove the *CString APIs, but testing them until
57+
// they are deleted.
58+
checkCString("");
59+
checkCString("a");
60+
checkCString("\n");
61+
checkCString("32");
62+
checkCString("321");
63+
checkCString("3210");
64+
checkCString("3210b");
65+
checkCString("123434");
66+
}
67+
3668
TEST(Parcel, NonNullTerminatedString8) {
3769
String8 kTestString = String8("test-is-good");
3870

0 commit comments

Comments
 (0)