mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 918808 part 2 - Remove cruft from InflateStringToBuffer. r=luke
This commit is contained in:
parent
c4e57290a4
commit
f5500cd71e
@ -134,16 +134,10 @@ class gcstats::StatisticsSerializer
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t outlen = nchars;
|
InflateStringToBuffer(buf, nchars, out);
|
||||||
bool ok = InflateStringToBuffer(NULL, buf, nchars, out, &outlen);
|
|
||||||
js_free(buf);
|
js_free(buf);
|
||||||
if (!ok) {
|
|
||||||
oom_ = true;
|
|
||||||
js_free(out);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
out[nchars] = 0;
|
|
||||||
|
|
||||||
|
out[nchars] = 0;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5463,7 +5463,25 @@ JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, size_
|
|||||||
{
|
{
|
||||||
AssertHeapIsIdle(cx);
|
AssertHeapIsIdle(cx);
|
||||||
CHECK_REQUEST(cx);
|
CHECK_REQUEST(cx);
|
||||||
return InflateStringToBuffer(cx, src, srclen, dst, dstlenp);
|
|
||||||
|
if (!dst) {
|
||||||
|
*dstlenp = srclen;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t dstlen = *dstlenp;
|
||||||
|
|
||||||
|
if (srclen > dstlen) {
|
||||||
|
InflateStringToBuffer(src, dstlen, dst);
|
||||||
|
|
||||||
|
AutoSuppressGC suppress(cx);
|
||||||
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BUFFER_TOO_SMALL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
InflateStringToBuffer(src, srclen, dst);
|
||||||
|
*dstlenp = srclen;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API(char *)
|
JS_PUBLIC_API(char *)
|
||||||
|
@ -388,13 +388,8 @@ js::AtomizeMaybeGC(ExclusiveContext *cx, const char *bytes, size_t length, Inter
|
|||||||
* js::AtomizeString rarely has to copy the temp string we make.
|
* js::AtomizeString rarely has to copy the temp string we make.
|
||||||
*/
|
*/
|
||||||
jschar inflated[ATOMIZE_BUF_MAX];
|
jschar inflated[ATOMIZE_BUF_MAX];
|
||||||
size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
|
InflateStringToBuffer(bytes, length, inflated);
|
||||||
if (!InflateStringToBuffer(cx->maybeJSContext(),
|
return AtomizeAndCopyChars<allowGC>(cx, inflated, length, ib);
|
||||||
bytes, length, inflated, &inflatedLength))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return AtomizeAndCopyChars<allowGC>(cx, inflated, inflatedLength, ib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jschar *tbcharsZ = InflateString(cx, bytes, &length);
|
jschar *tbcharsZ = InflateString(cx, bytes, &length);
|
||||||
|
@ -4164,29 +4164,6 @@ js::DeflateStringToBuffer(JSContext *maybecx, const jschar *src, size_t srclen,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
js::InflateStringToBuffer(JSContext *maybecx, const char *src, size_t srclen,
|
|
||||||
jschar *dst, size_t *dstlenp)
|
|
||||||
{
|
|
||||||
if (dst) {
|
|
||||||
size_t dstlen = *dstlenp;
|
|
||||||
if (srclen > dstlen) {
|
|
||||||
for (size_t i = 0; i < dstlen; i++)
|
|
||||||
dst[i] = (unsigned char) src[i];
|
|
||||||
if (maybecx) {
|
|
||||||
AutoSuppressGC suppress(maybecx);
|
|
||||||
JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL,
|
|
||||||
JSMSG_BUFFER_TOO_SMALL);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < srclen; i++)
|
|
||||||
dst[i] = (unsigned char) src[i];
|
|
||||||
}
|
|
||||||
*dstlenp = srclen;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ____ false
|
#define ____ false
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -249,15 +249,15 @@ extern jschar *
|
|||||||
InflateString(ThreadSafeContext *cx, const char *bytes, size_t *length);
|
InflateString(ThreadSafeContext *cx, const char *bytes, size_t *length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inflate bytes to JS chars in an existing buffer. 'chars' must be large
|
* Inflate bytes to JS chars in an existing buffer. 'dst' must be large
|
||||||
* enough for 'length' jschars. The buffer is NOT null-terminated.
|
* enough for 'srclen' jschars. The buffer is NOT null-terminated.
|
||||||
*
|
|
||||||
* charsLength must be be initialized with the destination buffer size and, on
|
|
||||||
* return, will contain on return the number of copied chars.
|
|
||||||
*/
|
*/
|
||||||
extern bool
|
inline void
|
||||||
InflateStringToBuffer(JSContext *maybecx, const char *bytes, size_t length,
|
InflateStringToBuffer(const char *src, size_t srclen, jschar *dst)
|
||||||
jschar *chars, size_t *charsLength);
|
{
|
||||||
|
for (size_t i = 0; i < srclen; i++)
|
||||||
|
dst[i] = (unsigned char) src[i];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deflate JS chars to bytes into a buffer. 'bytes' must be large enough for
|
* Deflate JS chars to bytes into a buffer. 'bytes' must be large enough for
|
||||||
|
@ -122,10 +122,7 @@ StringBuffer::appendInflated(const char *cstr, size_t cstrlen)
|
|||||||
size_t lengthBefore = length();
|
size_t lengthBefore = length();
|
||||||
if (!cb.growByUninitialized(cstrlen))
|
if (!cb.growByUninitialized(cstrlen))
|
||||||
return false;
|
return false;
|
||||||
mozilla::DebugOnly<size_t> oldcstrlen = cstrlen;
|
InflateStringToBuffer(cstr, cstrlen, begin() + lengthBefore);
|
||||||
mozilla::DebugOnly<bool> ok = InflateStringToBuffer(NULL, cstr, cstrlen,
|
|
||||||
begin() + lengthBefore, &cstrlen);
|
|
||||||
JS_ASSERT(ok && oldcstrlen == cstrlen);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user