From f02452db2bb18dc635adc625e7bc9deb588225df Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Wed, 22 Aug 2001 22:21:43 +0000 Subject: [PATCH] fix for strlen being called on a null string when there is no text to convert to the platform charset. r=pchen/sr=sfraser/a=asa. bug# 92755. --- widget/src/xpwidgets/nsPrimitiveHelpers.cpp | 23 +-------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/widget/src/xpwidgets/nsPrimitiveHelpers.cpp b/widget/src/xpwidgets/nsPrimitiveHelpers.cpp index 99905e218cea..5824d8157a3c 100644 --- a/widget/src/xpwidgets/nsPrimitiveHelpers.cpp +++ b/widget/src/xpwidgets/nsPrimitiveHelpers.cpp @@ -150,25 +150,6 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, if (NS_FAILED(rv)) platformCharset.AssignWithConversion("ISO-8859-1"); -#if 0 - // get the encoder - nsCOMPtr ccm = - do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeEncoder(&platformCharset, getter_AddRefs(encoder)); - - // Estimate out length and allocate the buffer based on a worst-case estimate, then do - // the conversion. - encoder->GetMaxLength(inUnicode, inUnicodeLen, outPlainTextLen); - if ( *outPlainTextLen ) { - *outPlainTextData = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(*outPlainTextLen + sizeof(char))); - if ( *outPlainTextData ) { - rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - rv = encoder->Convert(inUnicode, &inUnicodeLen, *outPlainTextData, outPlainTextLen); - (*outPlainTextData)[*outPlainTextLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length -#endif - // use transliterate to convert things like smart quotes to normal quotes for plain text nsCAutoString cPlatformCharset; cPlatformCharset.AssignWithConversion(platformCharset); @@ -180,9 +161,7 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, nsIEntityConverter::transliterate); converter->Convert(inUnicode, outPlainTextData); - - // XXX is there a better way to do this? - *outPlainTextLen = strlen(*outPlainTextData); + *outPlainTextLen = *outPlainTextData ? strlen(*outPlainTextData) : 0; NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting unicode to plain text" );