Bug 384803 nsStringBundle::FormatStringFromID should return nsMemory allocated strings

patch by prasad@medhas.org r=timeless r=smontagu sr=biesi
This commit is contained in:
timeless@mozdev.org 2007-07-01 12:29:43 -07:00
parent 90c5be45ec
commit 50d3c7abba

View File

@ -385,7 +385,7 @@ nsStringBundle::FormatString(const PRUnichar *aFormatStr,
// Don't believe me? See:
// http://www.eskimo.com/~scs/C-faq/q15.13.html
// -alecf
*aResult =
PRUnichar *text =
nsTextFormatter::smprintf(aFormatStr,
aLength >= 1 ? aParams[0] : nsnull,
aLength >= 2 ? aParams[1] : nsnull,
@ -397,7 +397,21 @@ nsStringBundle::FormatString(const PRUnichar *aFormatStr,
aLength >= 8 ? aParams[7] : nsnull,
aLength >= 9 ? aParams[8] : nsnull,
aLength >= 10 ? aParams[9] : nsnull);
return NS_OK;
if (!text) {
*aResult = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
// nsTextFormatter does not use the shared nsMemory allocator.
// Instead it is required to free the memory it allocates using
// nsTextFormatter::smprintf_free. Let's instead use nsMemory based
// allocation for the result that we give out and free the string
// returned by smprintf ourselves!
*aResult = NS_strdup(text);
nsTextFormatter::smprintf_free(text);
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMPL_ISUPPORTS1(nsExtensibleStringBundle, nsIStringBundle)