Bug 918808 part 2 - Remove cruft from InflateStringToBuffer. r=luke

This commit is contained in:
Jan de Mooij 2013-09-21 11:36:33 +02:00
parent c4e57290a4
commit f5500cd71e
6 changed files with 32 additions and 51 deletions

View File

@ -134,16 +134,10 @@ class gcstats::StatisticsSerializer
return NULL;
}
size_t outlen = nchars;
bool ok = InflateStringToBuffer(NULL, buf, nchars, out, &outlen);
InflateStringToBuffer(buf, nchars, out);
js_free(buf);
if (!ok) {
oom_ = true;
js_free(out);
return NULL;
}
out[nchars] = 0;
out[nchars] = 0;
return out;
}

View File

@ -5463,7 +5463,25 @@ JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst, size_
{
AssertHeapIsIdle(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 *)

View File

@ -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.
*/
jschar inflated[ATOMIZE_BUF_MAX];
size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
if (!InflateStringToBuffer(cx->maybeJSContext(),
bytes, length, inflated, &inflatedLength))
{
return NULL;
}
return AtomizeAndCopyChars<allowGC>(cx, inflated, inflatedLength, ib);
InflateStringToBuffer(bytes, length, inflated);
return AtomizeAndCopyChars<allowGC>(cx, inflated, length, ib);
}
jschar *tbcharsZ = InflateString(cx, bytes, &length);

View File

@ -4164,29 +4164,6 @@ js::DeflateStringToBuffer(JSContext *maybecx, const jschar *src, size_t srclen,
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
/*

View File

@ -249,15 +249,15 @@ extern jschar *
InflateString(ThreadSafeContext *cx, const char *bytes, size_t *length);
/*
* Inflate bytes to JS chars in an existing buffer. 'chars' must be large
* enough for 'length' 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.
* Inflate bytes to JS chars in an existing buffer. 'dst' must be large
* enough for 'srclen' jschars. The buffer is NOT null-terminated.
*/
extern bool
InflateStringToBuffer(JSContext *maybecx, const char *bytes, size_t length,
jschar *chars, size_t *charsLength);
inline void
InflateStringToBuffer(const char *src, size_t srclen, jschar *dst)
{
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

View File

@ -122,10 +122,7 @@ StringBuffer::appendInflated(const char *cstr, size_t cstrlen)
size_t lengthBefore = length();
if (!cb.growByUninitialized(cstrlen))
return false;
mozilla::DebugOnly<size_t> oldcstrlen = cstrlen;
mozilla::DebugOnly<bool> ok = InflateStringToBuffer(NULL, cstr, cstrlen,
begin() + lengthBefore, &cstrlen);
JS_ASSERT(ok && oldcstrlen == cstrlen);
InflateStringToBuffer(cstr, cstrlen, begin() + lengthBefore);
return true;
}