]> granicus.if.org Git - neomutt/commitdiff
Improve strcat usage (#2802).
authorSami Farin <safari-mutt@safari.iki.fi>
Mon, 12 Mar 2007 17:03:12 +0000 (10:03 -0700)
committerSami Farin <safari-mutt@safari.iki.fi>
Mon, 12 Mar 2007 17:03:12 +0000 (10:03 -0700)
ChangeLog
charset.c
copy.c
rfc822.c
rfc822.h

index e68e21545669b05cfc5fb0ae2f5141420f5c7215..3cafd08ae97ef64deb26744eaea23c9b9ed00767 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2007-03-11 11:54 +0100  Thomas Roessler  <roessler@does-not-exist.org>  (8a640badfb60)
+
+       * COPYRIGHT, build-release, crypt-gpgme.c, doc/applying-patches.txt,
+       doc/dotlock.man, doc/manual.xml.head, doc/muttrc.man.head,
+       muttbug.sh.in, po/bg.po, po/da.po, po/eo.po, po/es.po, po/et.po,
+       po/gl.po, po/it.po, po/lt.po, po/pt_BR.po, po/sk.po, po/zh_CN.po,
+       po/zh_TW.po: Grabage-collect references to an outdated email
+       address.
+
+2007-03-09 10:58 -0800  Rocco Rutte  <pdmef@gmx.net>  (d1122bbaacd8)
+
+       * doc/Makefile.am, doc/manual.xml.head: Make manual validate against
+       DocBook 4.2 DTD for "book" This adds a 'validate' target to
+       doc/Makefile which uses xmllint(1) to validate manual.xml against
+       the DTD given in the doctype (intended for developers only).
+
+       Running it revealed two validation errors which this patch fixes:
+
+       1) We declare 'article' as the doctype but want to use 'book' 2)
+       Within a lists's items, we didn't include our text in a paragraph
+
+2007-03-08 21:13 -0800  Michael Elkins  <me@mutt.org>  (0ec4394636c4)
+
+       * init.h: Add `UL' cast for Umask entry in MuttVars to supress
+       compiler warning.
+
+2007-03-08 12:19 -0800  Petr P\92sa?  <petr.pisar@atlas.cz>  (d0924f72d2e8)
+
+       * po/cs.po: Czech spelling fixes and new translations
+
+2007-03-07 12:18 -0800  Christoph Berg  <cb@df7cb.de>  (5de130a3cb96)
+
+       * ChangeLog, doc/muttrc.man.head: Typos in muttrc.man.head
+
 2007-03-07 12:11 -0800  Michael Tatge  <Michael.Tatge@web.de>  (162f0c127492)
 
        * doc/mutt.man: Document -d in the man page
index 25d4fa4dbb5c333230ed1bbe69e07353c21b3e73..8d483c97c3d7e3653b0849b71bd3668dca7dde26 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -245,6 +245,11 @@ void mutt_canonical_charset (char *dest, size_t dlen, const char *name)
   char *p;
   char scratch[LONG_STRING];
 
+  if (!ascii_strcasecmp (name, "utf-8")) {
+    strfcpy (dest, name, dlen);
+    goto found_utf8;
+  }
+
   /* catch some common iso-8859-something misspellings */
   if (!ascii_strncasecmp (name, "8859", 4) && name[4] != '-')
     snprintf (scratch, sizeof (scratch), "iso-8859-%s", name +4);
@@ -267,6 +272,7 @@ void mutt_canonical_charset (char *dest, size_t dlen, const char *name)
 
   strfcpy (dest, scratch, dlen);
 
+found_utf8:
   /* for cosmetics' sake, transform to lowercase. */
   for (p = dest; *p; p++)
     *p = ascii_tolower (*p);
diff --git a/copy.c b/copy.c
index e459a5543f9b342ef564bc2f258cb43f8d15eb94..53c0467f9d701fa9a7d65cbb426048801e28eb49 100644 (file)
--- 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)
index a1796b0abd1b87fbd1080bcf13cf41431ed7a0a7..fff3133c1b919524b061ef0311f932e4f25e9c8f 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -687,7 +687,7 @@ done:
 }
 
 /* note: it is assumed that `buf' is nul terminated! */
-void rfc822_write_address (char *buf, size_t buflen, ADDRESS *addr, int display)
+int rfc822_write_address (char *buf, size_t buflen, ADDRESS *addr, int display)
 {
   char *pbuf = buf;
   size_t len = mutt_strlen (buf);
@@ -739,6 +739,7 @@ void rfc822_write_address (char *buf, size_t buflen, ADDRESS *addr, int display)
   }
 done:
   *pbuf = 0;
+  return pbuf - buf;
 }
 
 /* this should be rfc822_cpy_adr */
index aa381182c8f8c24f27ad432af0a798c5815af793..3c8d176570df2c212f67fa69d02940ad0bfa4b8b 100644 (file)
--- a/rfc822.h
+++ b/rfc822.h
@@ -48,7 +48,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *, const char *s);
 ADDRESS *rfc822_cpy_adr (ADDRESS *addr);
 ADDRESS *rfc822_cpy_adr_real (ADDRESS *addr);
 ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b);
-void rfc822_write_address (char *, size_t, ADDRESS *, int);
+int rfc822_write_address (char *, size_t, ADDRESS *, int);
 void rfc822_write_address_single (char *, size_t, ADDRESS *, int);
 void rfc822_free_address (ADDRESS **addr);
 void rfc822_cat (char *, size_t, const char *, const char *);