File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change @@ -33,6 +33,38 @@ using android::String8;
3333using android::binder::Status;
3434using 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+
3668TEST (Parcel, NonNullTerminatedString8) {
3769 String8 kTestString = String8 (" test-is-good" );
3870
You can’t perform that action at this time.
0 commit comments