fix 362512 issues with rfc2047 encoding, sr=mscott

This commit is contained in:
bienvenu%nventure.com 2006-12-01 19:24:22 +00:00
Родитель 65e1e808a2
Коммит b9fe1fa76c
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -592,13 +592,19 @@ char * apply_rfc2047_encoding(const char *_src, PRBool structured, const char *c
if (!_src) if (!_src)
return nsnull; return nsnull;
if ((src = src_head = nsCRT::strdup(_src)) == nsnull)
//<TAB>=?<charset>?<B/Q>?...?=<CRLF>
PRInt32 perLineOverhead = strlen(charset) + 10;
if (perLineOverhead > foldlen || (src = src_head = nsCRT::strdup(_src)) == nsnull)
return nsnull; return nsnull;
/* allocate enough buffer for conversion, this way it can avoid /* allocate enough buffer for conversion, this way it can avoid
do another memory allocation which is expensive 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) { if ((outputtail = output = (char *)PR_Malloc(outputlen)) == nsnull) {
PR_Free(src_head); PR_Free(src_head);
return nsnull; return nsnull;