Fixes for memory alloc error in charset functions

This commit is contained in:
Michiel Broek
2003-01-23 22:57:16 +00:00
parent dfe85b13fc
commit 1941e57b6e
5 changed files with 32 additions and 61 deletions

View File

@@ -139,29 +139,27 @@ char *strnkconv(const char *src, int incode, int outcode, int n)
char *strkconv(const char *src, int incode, int outcode)
{
static char *dest;
static char *dest;
int bytes = 1;
if ((incode==outcode) && (incode!=CHRS_NOTSET) && (incode!=CHRS_AUTODETECT))
return (char *)src;
if ((incode==outcode) && (incode!=CHRS_NOTSET) && (incode!=CHRS_AUTODETECT))
return (char *)src;
if (!src)
return NULL;
if (!src)
return NULL;
if((incode == CHRS_AUTODETECT) || (incode == CHRS_NOTSET)) {
if (LANG_BITS == 16) {
incode = iso2022_detectcode((char *)src,incode);
}
if((incode == CHRS_AUTODETECT) || (incode == CHRS_NOTSET)) {
if (LANG_BITS == 16) {
bytes = 2;
incode = iso2022_detectcode((char *)src,incode);
}
}
if(dest)
free(dest);
/* FIXME: should be
* dest = (char *)malloc((strlen(src) + 1) + (6 * "number of \n + 1"));
*/
dest = (char *)malloc(((strlen(src) + 1) * 2) + 6 );
kconv((char *)src, &dest, incode, outcode);
return dest;
if(dest)
free(dest);
dest = (char *)malloc((strlen(src) + 1) + ((6 * bytes) + 1));
kconv((char *)src, &dest, incode, outcode);
return dest;
}

View File

@@ -386,41 +386,3 @@ void writechrs(int code, FILE *pkt, int ispkt)
}
// WORDT NIET GEBRUIKT ??
void writecharset(int code, FILE *pip, rfcmsg *msg, rfcmsg *kmsg)
{
char *p, *charset=NULL;
charset=getcharset(code);
if ((p=hdr((char *)"Mime-Version",msg))) fprintf(pip,(char *)"Mime-Version:%s",p);
else if ((p=hdr((char *)"RFC-Mime-Version",kmsg))) fprintf(pip,(char *)"Mime-Version: %s",p);
else if ((p=hdr((char *)"Mime-Version",kmsg))) fprintf(pip,(char *)"Mime-Version: %s",p);
else if ((charset) && (code != CHRS_NOTSET)) fprintf(pip,"Mime-Version: 1.0\n");
if ((p=hdr((char *)"Content-Type",msg))) fprintf(pip,"Content-Type:%s",p);
else if ((p=hdr((char *)"RFC-Content-Type",kmsg))) fprintf(pip,"Content-Type: %s",p);
else if ((p=hdr((char *)"Content-Type",kmsg))) fprintf(pip,"Content-Type: %s",p);
else if ((charset) && (code != CHRS_NOTSET))
{
if ((p=hdr((char *)"FSCHTML",kmsg)) || (p=hdr((char *)"HTML",kmsg)))
fprintf(pip,"Content-Type: text/html; charset=%s\n",charset);
else
fprintf(pip,"Content-Type: text/plain; charset=%s\n",charset);
}
if ((p=hdr((char *)"Content-Length",msg))) fprintf(pip,"Content-Length%s",p);
else if ((p=hdr((char *)"RFC-Content-Length",kmsg))) fprintf(pip,"Content-Length: %s",p);
else if ((p=hdr((char *)"Content-Length",kmsg))) fprintf(pip,"Content-Length: %s",p);
if ((p=hdr((char *)"Content-Transfer-Encoding",msg))) fprintf(pip,"Content-Transfer-Encoding:%s",p);
else if ((p=hdr((char *)"RFC-Content-Transfer-Encoding",kmsg))) fprintf(pip,"Content-Transfer-Encoding: %s",p);
else if ((p=hdr((char *)"Content-Transfer-Encoding",kmsg))) fprintf(pip,"Content-Transfer-Encoding: %s",p);
else if ((charset) && (code == CHRS_ISO_8859_1_QP)) fprintf(pip,"Content-Transfer-Encoding: quoted-printable\n");
else if ((charset) && (code != CHRS_NOTSET)) { fprintf(pip,"Content-Transfer-Encoding: ");
if ((code == CHRS_ASCII || code == CHRS_UTF_7)) fprintf(pip,"7bit\n");
else if (strncasecmp(charset,"iso-2022-",9) == 0) fprintf(pip,"7bit\n");
else fprintf(pip,"8bit\n"); /* all others are 8 bit */
}
}