summaryrefslogtreecommitdiffstats
path: root/copy.c
diff options
context:
space:
mode:
authorSami Farin <safari-mutt@safari.iki.fi>2007-03-12 10:03:12 -0700
committerSami Farin <safari-mutt@safari.iki.fi>2007-03-12 10:03:12 -0700
commitb3813a6b4cb511047e0388bf252c551cbfef9b34 (patch)
tree25ee0b9256f841ef078e84824eabba79e7e41375 /copy.c
parentb881ce1f4bda001cd69d7f1c949f2213e34a97cb (diff)
Improve strcat usage (#2802).
Diffstat (limited to 'copy.c')
-rw-r--r--copy.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/copy.c b/copy.c
index e459a554..53c0467f 100644
--- a/copy.c
+++ b/copy.c
@@ -49,13 +49,14 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
int from = 0;
int this_is_from;
int ignore = 0;
- char buf[STRING]; /* should be long enough to get most fields in one pass */
+ char buf[LONG_STRING]; /* should be long enough to get most fields in one pass */
char *nl;
LIST *t;
char **headers;
int hdr_count;
int x;
char *this_one = NULL;
+ size_t this_one_len;
int error;
if (ftello (in) != off_start)
@@ -156,15 +157,17 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
{
if (!address_header_decode (&this_one))
rfc2047_decode (&this_one);
+ this_one_len = mutt_strlen (this_one);
}
-
+
if (!headers[x])
headers[x] = this_one;
else
{
- safe_realloc (&headers[x], mutt_strlen (headers[x]) +
- mutt_strlen (this_one) + sizeof (char));
- strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
+ int hlen = mutt_strlen (headers[x]);
+
+ safe_realloc (&headers[x], hlen + this_one_len + sizeof (char));
+ strcat (headers[x] + hlen, this_one); /* __STRCAT_CHECKED__ */
FREE (&this_one);
}
@@ -231,13 +234,15 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
if (!ignore)
{
dprint (2, (debugfile, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count));
- if (!this_one)
+ if (!this_one) {
this_one = safe_strdup (buf);
- else
- {
- safe_realloc (&this_one,
- mutt_strlen (this_one) + mutt_strlen (buf) + sizeof (char));
- strcat (this_one, buf); /* __STRCAT_CHECKED__ */
+ this_one_len = mutt_strlen (this_one);
+ } else {
+ int blen = mutt_strlen (buf);
+
+ safe_realloc (&this_one, this_one_len + blen + sizeof (char));
+ strcat (this_one + this_one_len, buf); /* __STRCAT_CHECKED__ */
+ this_one_len += blen;
}
}
} /* while (ftello (in) < off_end) */
@@ -255,9 +260,10 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
headers[x] = this_one;
else
{
- safe_realloc (&headers[x], mutt_strlen (headers[x]) +
- mutt_strlen (this_one) + sizeof (char));
- strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
+ int hlen = mutt_strlen (headers[x]);
+
+ safe_realloc (&headers[x], hlen + this_one_len + sizeof (char));
+ strcat (headers[x] + hlen, this_one); /* __STRCAT_CHECKED__ */
FREE (&this_one);
}
@@ -845,22 +851,22 @@ static void format_address_header (char **h, ADDRESS *a)
char buf[HUGE_STRING];
char cbuf[STRING];
char c2buf[STRING];
-
- int l, linelen, buflen, count;
+ char *p;
+ int l, linelen, buflen, count, cbuflen, c2buflen, plen;
+
linelen = mutt_strlen (*h);
+ plen = linelen;
buflen = linelen + 3;
-
-
+
safe_realloc (h, buflen);
for (count = 0; a; a = a->next, count++)
{
ADDRESS *tmp = a->next;
a->next = NULL;
*buf = *cbuf = *c2buf = '\0';
- rfc822_write_address (buf, sizeof (buf), a, 0);
+ l = rfc822_write_address (buf, sizeof (buf), a, 0);
a->next = tmp;
- l = mutt_strlen (buf);
if (count && linelen + l > 74)
{
strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */
@@ -881,16 +887,22 @@ static void format_address_header (char **h, ADDRESS *a)
buflen++;
strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */
}
-
- buflen += l + mutt_strlen (cbuf) + mutt_strlen (c2buf);
+
+ cbuflen = mutt_strlen (cbuf);
+ c2buflen = mutt_strlen (c2buf);
+ buflen += l + cbuflen + c2buflen;
safe_realloc (h, buflen);
- strcat (*h, cbuf); /* __STRCAT_CHECKED__ */
- strcat (*h, buf); /* __STRCAT_CHECKED__ */
- strcat (*h, c2buf); /* __STRCAT_CHECKED__ */
+ p = *h;
+ strcat (p + plen, cbuf); /* __STRCAT_CHECKED__ */
+ plen += cbuflen;
+ strcat (p + plen, buf); /* __STRCAT_CHECKED__ */
+ plen += l;
+ strcat (p + plen, c2buf); /* __STRCAT_CHECKED__ */
+ plen += c2buflen;
}
/* Space for this was allocated in the beginning of this function. */
- strcat (*h, "\n"); /* __STRCAT_CHECKED__ */
+ strcat (p + plen, "\n"); /* __STRCAT_CHECKED__ */
}
static int address_header_decode (char **h)