diff --git a/mozilla/mailnews/mime/src/comi18n.cpp b/mozilla/mailnews/mime/src/comi18n.cpp index 2b521037a1f..b3c21652b0f 100644 --- a/mozilla/mailnews/mime/src/comi18n.cpp +++ b/mozilla/mailnews/mime/src/comi18n.cpp @@ -594,13 +594,19 @@ char * apply_rfc2047_encoding(const char *_src, PRBool structured, const char *c if (!_src) return nsnull; - if ((src = src_head = nsCRT::strdup(_src)) == nsnull) + + //=???...?= + PRInt32 perLineOverhead = strlen(charset) + 10; + + if (perLineOverhead > foldlen || (src = src_head = nsCRT::strdup(_src)) == nsnull) return nsnull; /* allocate enough buffer for conversion, this way it can avoid do another memory allocation which is expensive */ - outputlen = strlen(src) * 4 + kMAX_CSNAME + 8; + PRInt32 charsPerLine = (foldlen - perLineOverhead) / 4; + PRInt32 maxNumLines = (strlen(src) / charsPerLine) + 1; + outputlen = strlen(src) * 4 + (maxNumLines * perLineOverhead) + 20 /* fudge */; if ((outputtail = output = (char *)PR_Malloc(outputlen)) == nsnull) { PR_Free(src_head); return nsnull;