]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | diff -ur sysklogd-1.4.1.orig/syslogd.c sysklogd-1.4.1/syslogd.c |
2 | --- sysklogd-1.4.1.orig/syslogd.c Sun Mar 11 19:40:10 2001 | |
3 | +++ sysklogd-1.4.1/syslogd.c Sun Apr 18 01:42:21 2004 | |
4 | @@ -1254,30 +1254,26 @@ | |
5 | crunch_list(list) | |
6 | char *list; | |
7 | { | |
8 | - int count, i; | |
9 | + int i, m, n; | |
10 | char *p, *q; | |
11 | char **result = NULL; | |
12 | ||
13 | p = list; | |
14 | ||
15 | /* strip off trailing delimiters */ | |
16 | - while (p[strlen(p)-1] == LIST_DELIMITER) { | |
17 | - count--; | |
18 | + while (*p && p[strlen(p)-1] == LIST_DELIMITER) | |
19 | p[strlen(p)-1] = '\0'; | |
20 | - } | |
21 | /* cut off leading delimiters */ | |
22 | - while (p[0] == LIST_DELIMITER) { | |
23 | - count--; | |
24 | + while (p[0] == LIST_DELIMITER) | |
25 | p++; | |
26 | - } | |
27 | ||
28 | - /* count delimiters to calculate elements */ | |
29 | - for (count=i=0; p[i]; i++) | |
30 | - if (p[i] == LIST_DELIMITER) count++; | |
31 | + /* count delimiters to calculate the number of elements */ | |
32 | + for (n = i = 0; p[i]; i++) | |
33 | + if (p[i] == LIST_DELIMITER) n++; | |
34 | ||
35 | - if ((result = (char **)malloc(sizeof(char *) * count+2)) == NULL) { | |
36 | + if ((result = (char **)malloc(sizeof(char *) * (n + 2))) == NULL) { | |
37 | printf ("Sorry, can't get enough memory, exiting.\n"); | |
38 | - exit(0); | |
39 | + exit(1); | |
40 | } | |
41 | ||
42 | /* | |
43 | @@ -1285,30 +1281,28 @@ | |
44 | * characters are different from any delimiters, | |
45 | * so we don't have to care about this. | |
46 | */ | |
47 | - count = 0; | |
48 | - while ((q=strchr(p, LIST_DELIMITER))) { | |
49 | - result[count] = (char *) malloc((q - p + 1) * sizeof(char)); | |
50 | - if (result[count] == NULL) { | |
51 | + m = 0; | |
52 | + while ((q = strchr(p, LIST_DELIMITER)) && m < n) { | |
53 | + result[m] = (char *) malloc((q - p + 1) * sizeof(char)); | |
54 | + if (result[m] == NULL) { | |
55 | printf ("Sorry, can't get enough memory, exiting.\n"); | |
56 | - exit(0); | |
57 | + exit(1); | |
58 | } | |
59 | - strncpy(result[count], p, q - p); | |
60 | - result[count][q - p] = '\0'; | |
61 | + memcpy(result[m], p, q - p); | |
62 | + result[m][q - p] = '\0'; | |
63 | p = q; p++; | |
64 | - count++; | |
65 | + m++; | |
66 | } | |
67 | - if ((result[count] = \ | |
68 | - (char *)malloc(sizeof(char) * strlen(p) + 1)) == NULL) { | |
69 | + if ((result[m] = strdup(p)) == NULL) { | |
70 | printf ("Sorry, can't get enough memory, exiting.\n"); | |
71 | - exit(0); | |
72 | + exit(1); | |
73 | } | |
74 | - strcpy(result[count],p); | |
75 | - result[++count] = NULL; | |
76 | + result[++m] = NULL; | |
77 | ||
78 | #if 0 | |
79 | - count=0; | |
80 | - while (result[count]) | |
81 | - dprintf ("#%d: %s\n", count, StripDomains[count++]); | |
82 | + m = 0; | |
83 | + while (result[m]) | |
84 | + dprintf ("#%d: %s\n", m, result[m++]); | |
85 | #endif | |
86 | return result; | |
87 | } |