Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: Commit

system/core


Commit MetaInfo

Revisión554678e9a1a5e94c8307a5d89445ce0beab70d2f (tree)
Tiempo2018-04-14 07:47:59
Autorandroid-build-team Robot <android-build-team-robot@goog...>
Commiterandroid-build-team Robot

Log Message

Merge cherrypicks of [3898937, 3898958, 3899077, 3897885, 3898496, 3898245, 3898959, 3898960, 3897790, 3898312, 3898313, 3898314, 3899155, 3899156, 3899157, 3898289, 3898290, 3899061, 3898291, 3898292, 3896951, 3899158, 3898961, 3898938, 3898246] into sparse-4657601-L30800000163316240

Change-Id: Ie16e11a09ca90e182f5ca14fdde1f8b2c56b77f0

Cambiar Resumen

Diferencia incremental

--- a/libutils/String16.cpp
+++ b/libutils/String16.cpp
@@ -79,6 +79,23 @@ static char16_t* allocFromUTF8(const char* u8str, size_t u8len)
7979 return getEmptyString();
8080 }
8181
82+static char16_t* allocFromUTF16(const char16_t* u16str, size_t u16len) {
83+ if (u16len >= SIZE_MAX / sizeof(char16_t)) {
84+ android_errorWriteLog(0x534e4554, "73826242");
85+ abort();
86+ }
87+
88+ SharedBuffer* buf = SharedBuffer::alloc((u16len + 1) * sizeof(char16_t));
89+ ALOG_ASSERT(buf, "Unable to allocate shared buffer");
90+ if (buf) {
91+ char16_t* str = (char16_t*)buf->data();
92+ memcpy(str, u16str, u16len * sizeof(char16_t));
93+ str[u16len] = 0;
94+ return str;
95+ }
96+ return getEmptyString();
97+}
98+
8299 // ---------------------------------------------------------------------------
83100
84101 String16::String16()
@@ -111,35 +128,9 @@ String16::String16(const String16& o, size_t len, size_t begin)
111128 setTo(o, len, begin);
112129 }
113130
114-String16::String16(const char16_t* o)
115-{
116- size_t len = strlen16(o);
117- SharedBuffer* buf = SharedBuffer::alloc((len+1)*sizeof(char16_t));
118- ALOG_ASSERT(buf, "Unable to allocate shared buffer");
119- if (buf) {
120- char16_t* str = (char16_t*)buf->data();
121- strcpy16(str, o);
122- mString = str;
123- return;
124- }
125-
126- mString = getEmptyString();
127-}
128-
129-String16::String16(const char16_t* o, size_t len)
130-{
131- SharedBuffer* buf = SharedBuffer::alloc((len+1)*sizeof(char16_t));
132- ALOG_ASSERT(buf, "Unable to allocate shared buffer");
133- if (buf) {
134- char16_t* str = (char16_t*)buf->data();
135- memcpy(str, o, len*sizeof(char16_t));
136- str[len] = 0;
137- mString = str;
138- return;
139- }
131+String16::String16(const char16_t* o) : mString(allocFromUTF16(o, strlen16(o))) {}
140132
141- mString = getEmptyString();
142-}
133+String16::String16(const char16_t* o, size_t len) : mString(allocFromUTF16(o, len)) {}
143134
144135 String16::String16(const String8& o)
145136 : mString(allocFromUTF8(o.string(), o.size()))
@@ -201,6 +192,11 @@ status_t String16::setTo(const char16_t* other)
201192
202193 status_t String16::setTo(const char16_t* other, size_t len)
203194 {
195+ if (len >= SIZE_MAX / sizeof(char16_t)) {
196+ android_errorWriteLog(0x534e4554, "73826242");
197+ abort();
198+ }
199+
204200 SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
205201 ->editResize((len+1)*sizeof(char16_t));
206202 if (buf) {
@@ -224,6 +220,11 @@ status_t String16::append(const String16& other)
224220 return NO_ERROR;
225221 }
226222
223+ if (myLen >= SIZE_MAX / sizeof(char16_t) - otherLen) {
224+ android_errorWriteLog(0x534e4554, "73826242");
225+ abort();
226+ }
227+
227228 SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
228229 ->editResize((myLen+otherLen+1)*sizeof(char16_t));
229230 if (buf) {
@@ -245,6 +246,11 @@ status_t String16::append(const char16_t* chrs, size_t otherLen)
245246 return NO_ERROR;
246247 }
247248
249+ if (myLen >= SIZE_MAX / sizeof(char16_t) - otherLen) {
250+ android_errorWriteLog(0x534e4554, "73826242");
251+ abort();
252+ }
253+
248254 SharedBuffer* buf = SharedBuffer::bufferFromData(mString)
249255 ->editResize((myLen+otherLen+1)*sizeof(char16_t));
250256 if (buf) {
Show on old repository browser