91744 - Avoid stack overflow by replacing recursion with a simple do-while. Removed unwanted assertions. r=heikki,sr=vidur

This commit is contained in:
harishd%netscape.com 2001-09-14 20:48:25 +00:00
parent 1f8f8d5c07
commit 1936f6c0d2
2 changed files with 66 additions and 30 deletions

View File

@ -1546,18 +1546,22 @@ nsresult ConsumeAttributeValueText(nsString& aString,
const nsReadEndCondition& aEndCondition,
PRInt32 aFlag)
{
nsresult result=aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
if(NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
if(ch==kAmpersand) {
result=ConsumeAttributeEntity(aString,aScanner,aFlag);
if (NS_SUCCEEDED(result)) {
result=ConsumeAttributeValueText(aString,aScanner,aEndCondition,aFlag);
nsresult result = NS_OK;
PRBool done = PR_FALSE;
do {
result = aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
if(NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
if(ch == kAmpersand) {
result = ConsumeAttributeEntity(aString,aScanner,aFlag);
}
else {
done = PR_TRUE;
}
}
}
} while (NS_SUCCEEDED(result) && !done);
return result;
}
@ -1934,7 +1938,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
do {
result=aScanner.GetChar(aChar);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
aString.Append(aChar);
if(aChar==kRightBrace)
@ -1947,7 +1954,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
PRUnichar theChar=0;
if (kHashsign==aChar) {
result = aScanner.Peek(theChar,2);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if (nsCRT::IsAsciiDigit(theChar)) {
aScanner.GetChar(aChar); // Consume &
@ -1969,7 +1979,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
}
else {
result = aScanner.Peek(theChar,1);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if(nsCRT::IsAsciiAlpha(theChar) ||
theChar == '_' ||
@ -1983,10 +1996,15 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
}
}
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
result=aScanner.Peek(aChar);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if (aChar == kSemicolon) {
// consume semicolon that stopped the scan

View File

@ -1546,18 +1546,22 @@ nsresult ConsumeAttributeValueText(nsString& aString,
const nsReadEndCondition& aEndCondition,
PRInt32 aFlag)
{
nsresult result=aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
if(NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
if(ch==kAmpersand) {
result=ConsumeAttributeEntity(aString,aScanner,aFlag);
if (NS_SUCCEEDED(result)) {
result=ConsumeAttributeValueText(aString,aScanner,aEndCondition,aFlag);
nsresult result = NS_OK;
PRBool done = PR_FALSE;
do {
result = aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
if(NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
if(ch == kAmpersand) {
result = ConsumeAttributeEntity(aString,aScanner,aFlag);
}
else {
done = PR_TRUE;
}
}
}
} while (NS_SUCCEEDED(result) && !done);
return result;
}
@ -1934,7 +1938,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
do {
result=aScanner.GetChar(aChar);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
aString.Append(aChar);
if(aChar==kRightBrace)
@ -1947,7 +1954,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
PRUnichar theChar=0;
if (kHashsign==aChar) {
result = aScanner.Peek(theChar,2);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if (nsCRT::IsAsciiDigit(theChar)) {
aScanner.GetChar(aChar); // Consume &
@ -1969,7 +1979,10 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
}
else {
result = aScanner.Peek(theChar,1);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if(nsCRT::IsAsciiAlpha(theChar) ||
theChar == '_' ||
@ -1983,10 +1996,15 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
}
}
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
result=aScanner.Peek(aChar);
NS_ENSURE_SUCCESS(result,result);
if (NS_FAILED(result)) {
return result;
}
if (aChar == kSemicolon) {
// consume semicolon that stopped the scan