bail out with a violated assertion in case of error
#include <string.h>
#include <ctype.h>
#include "charset.h"
#include <string.h>
#include <ctype.h>
#include "charset.h"
int encoding;
char *inp, *outp, *encstart, *wordp, *encp, *endp;
char *decode;
int encoding;
char *inp, *outp, *encstart, *wordp, *encp, *endp;
char *decode;
+ inp = buf;
+
+ outlen = strlen(buf)+1;
+ if ((output = (char *)malloc(outlen)) == NULL) {
+ perror ("malloc");
+ return buf;
+ }
+
+ memset(output, 0, outlen);
+ outp = output;
while ((encstart = strstr (inp, "=?"))) {
while ((encstart = strstr (inp, "=?"))) {
- if (inp == outp)
- outp = encstart;
- else {
- memmove (outp, inp, encstart-inp-1);
+ if (encstart != inp) {
+ memcpy (outp, inp, encstart-inp-1);
outp += encstart-inp-1;
}
charset = encstart+2;
if ((encp = strchr (charset, '?')) == NULL) {
outp += encstart-inp-1;
}
charset = encstart+2;
if ((encp = strchr (charset, '?')) == NULL) {
- memmove (outp, inp, strlen(inp)+1);
+ memcpy (outp, inp, strlen(inp)+1);
break;
}
*encp = '\0';
if ((encp + 3 >= endp) || !strchr ("BbQq", *encp) || (*(encp+2) != '?')) {
break;
}
*encp = '\0';
if ((encp + 3 >= endp) || !strchr ("BbQq", *encp) || (*(encp+2) != '?')) {
- memmove (outp, inp, strlen(inp)+1);
+ *encp = '?';
+ memcpy (outp, inp, strlen(inp)+1);
+ outp += strlen(inp)+1;
+ inp += strlen(inp)+1;
inp = encp + 3;
if ((wordp = strstr (inp, "?=")) == NULL) {
inp = encp + 3;
if ((wordp = strstr (inp, "?=")) == NULL) {
- memmove (outp, encstart, strlen(encstart)+1);
- strcat (outp, "?");
- encstart += strlen(encstart)+1;
- memmove (outp, encstart, strlen(encstart)+1);
+ memcpy (outp, inp, strlen(inp)+1);
+ outp += strlen(inp)+1;
+ inp += strlen(inp)+1;
- size = wordp - outp -1;
+ size = outlen - strlen(output);
decode = convert_word (charset, decode, outp, size);
decode = convert_word (charset, decode, outp, size);
- memmove (outp, decode, strlen(decode));
outp += strlen(decode);
inp = wordp;
}
outp += strlen(decode);
inp = wordp;
}
- if (inp != outp)
- memmove (outp, inp, strlen(inp)+1);
+ if (strlen(inp))
+ memcpy (outp, inp, strlen(inp)+1);
+
+ memcpy (buf, output, strlen(output)+1);
+ free (output);