Make nsJSONWriter::Write not crash when given buffer greater than 1024 characters. b=423152 r=sayrer a=beltzner

git-svn-id: svn://10.0.0.236/trunk@248010 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%dbaron.org
2008-03-17 18:58:39 +00:00
parent 91b223fb17
commit 670292513c
2 changed files with 10 additions and 4 deletions

View File

@@ -417,7 +417,7 @@ nsJSON::ToJSON(JSContext *cx, jsval *vp)
{
// Now we check to see whether the return value implements toJSON()
JSBool ok = JS_TRUE;
char *toJSON = "toJSON";
const char *toJSON = "toJSON";
if (!JSVAL_IS_PRIMITIVE(*vp)) {
JSObject *obj = JSVAL_TO_OBJECT(*vp);
@@ -537,8 +537,13 @@ nsJSONWriter::Write(const PRUnichar *aBuffer, PRUint32 aLength)
mBufferCount = 0;
}
memcpy(&mBuffer[mBufferCount], aBuffer, aLength * sizeof(PRUnichar));
mBufferCount += aLength;
if (JSON_PARSER_BUFSIZE <= aLength) {
// we know mBufferCount is 0 because we know we hit the if above
mOutputString.Append(aBuffer, aLength);
} else {
memcpy(&mBuffer[mBufferCount], aBuffer, aLength * sizeof(PRUnichar));
mBufferCount += aLength;
}
return NS_OK;
}

File diff suppressed because one or more lines are too long