masqmail-0.2

view src/libident/support.c @ 179:ec3fe72a3e99

Fixed an important bug with folded headers! g_strconcat() returns a *copy* of the string, but hdr->value still pointed to the old header (which probably was a memory leak, too). If the folded part had been quite small it was likely that the new string was at the same position as the old one, thus making everything go well. But if pretty long headers were folded several times it was likely that the new string was allocated somewhere else in memory, thus breaking things. In result mails to lots of recipients (folded header) were frequently only sent to the ones in the first line. Sorry for the inconvenience.
author meillo@marmaro.de
date Fri, 03 Jun 2011 09:52:17 +0200
parents 08114f7dcc23
children
line source
1 /*
2 ** support.c
3 **
4 ** Author: Pr Emanuelsson <pell@lysator.liu.se>
5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
6 */
7 #include <stdio.h>
8 #include <ctype.h>
10 #ifdef HAVE_ANSIHEADERS
11 # include <stdlib.h>
12 # include <string.h>
13 #else
14 # define strchr(str, c) index(str, c)
15 #endif
17 #define IN_LIBIDENT_SRC
18 #include "ident.h"
21 char*
22 id_strdup __P1(char *, str)
23 {
24 char *cp;
26 cp = (char *) malloc(strlen(str) + 1);
27 if (cp == NULL) {
28 #ifdef DEBUG
29 perror("libident: malloc");
30 #endif
31 return NULL;
32 }
34 strcpy(cp, str);
36 return cp;
37 }
40 char*
41 id_strtok __P3(char *, cp, char *, cs, char *, dc)
42 {
43 static char *bp = 0;
45 if (cp)
46 bp = cp;
48 /*
49 ** No delimitor cs - return whole buffer and point at end
50 */
51 if (!cs) {
52 while (*bp)
53 bp++;
54 return cs;
55 }
57 /*
58 ** Skip leading spaces
59 */
60 while (isspace(*bp))
61 bp++;
63 /*
64 ** No token found?
65 */
66 if (!*bp)
67 return 0;
69 cp = bp;
70 while (*bp && !strchr(cs, *bp))
71 bp++;
73 /*
74 ** Remove trailing spaces
75 */
76 *dc = *bp;
77 for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
78 *++dc = '\0';
80 bp++;
82 return cp;
83 }