make code more readable.
authorPierre Habouzit <madcoder@debian.org>
Mon, 30 Oct 2006 16:19:45 +0000 (17:19 +0100)
committerPierre Habouzit <madcoder@debian.org>
Mon, 30 Oct 2006 16:19:45 +0000 (17:19 +0100)
fix a bug with uninitialized values.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
sendlib.c

index 0f17bf8..a461354 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -808,7 +808,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
   CONTENT_STATE state;
   FILE *fp = NULL;
   char *fromcode = NULL;
   CONTENT_STATE state;
   FILE *fp = NULL;
   char *fromcode = NULL;
-  char *tocode;
+  char *tocode = NULL;
   char buffer[100];
   char chsbuf[STRING];
   size_t r;
   char buffer[100];
   char chsbuf[STRING];
   size_t r;
@@ -1681,100 +1681,98 @@ const char *mutt_fqdn (short may_hide_host)
   return p;
 }
 
   return p;
 }
 
-static char mutt_normalized_char (char c)
+/* normalized character (we're stricter than RFC2822, 3.6.4) */
+static char mutt_normalized_char(char c)
 {
 {
-  if (isalnum (c))
-    return c;
-  if (strchr (".!#$%&'*+-/=?^_`{|}~", c))
-    return c;
-  return '.';                   /* normalized character (we're stricter than RFC2822, 3.6.4) */
+    return (isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.';
 }
 
 }
 
-static void mutt_gen_localpart(char *buf, unsigned int len, char *fmt)
+static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt)
 {
 {
+#define APPEND_FMT(fmt, arg) \
+        if (len > 1) {                                  \
+            int snlen = snprintf(buf, len, fmt, arg);   \
+            buf += snlen;                               \
+            len -= snlen;                               \
+        }
+
+#define APPEND_BYTE(c) \
+        if (len > 1) {                                  \
+            *buf++ = c;                                 \
+            *buf   = '\0';                              \
+            len--;                                      \
+        }
+
     time_t now;
     struct tm *tm;
     time_t now;
     struct tm *tm;
-    int snlen;
-
-    *buf = '\0';
 
     now = time (NULL);
     tm = gmtime (&now);
 
 
     now = time (NULL);
     tm = gmtime (&now);
 
-    for (; *fmt; ++fmt) {
-#define APPEND_FMT(fmt, ...) \
-        if (len > 0) {                                             \
-            snlen = snprintf(buf, len, fmt, ##__VA_ARGS__);        \
-            buf += snlen;                                          \
-            len -= snlen;                                          \
-        }
+    while (*fmt) {
+        int c = *fmt++;
 
 
-#define APPEND_BYTE(c) \
-        if (len > 1) {                                             \
-            *buf++ = c;                                            \
-            *buf   = '\0';                                         \
-            len--;                                                 \
+        if (c != '%') {
+            APPEND_BYTE(mutt_normalized_char(c));
+            continue;
         }
 
         }
 
-        if (*fmt == '%') {
-            switch (fmt[1]) {
-              case 0:
-                return;
-              case 'd':
-                APPEND_FMT("%02d", tm->tm_mday);
-                break;
-              case 'h':
-                APPEND_FMT("%02d", tm->tm_hour);
-                break;
-              case 'm':
-                APPEND_FMT("%02d", tm->tm_mon + 1);
-                break;
-              case 'M':
-                APPEND_FMT("%02d", tm->tm_min);
-                break;
-              case 'O':
-                APPEND_FMT("%lo", (unsigned long)now);
-                break;
-              case 'p':
-                APPEND_FMT("%u", (unsigned int)getpid());
-                break;
-              case 'P':
-                APPEND_FMT("%c", MsgIdPfx);
-                MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1;
-                break;
-              case 'r':
-                APPEND_FMT("%u", (unsigned int)rand());
-                break;
-              case 'R':
-                APPEND_FMT("%x", (unsigned int)rand());
-                break;
-              case 's':
-                APPEND_FMT("%02d", tm->tm_sec);
-                break;
-              case 'T':
-                APPEND_FMT("%u", (unsigned int) now);
-                break;
-              case 'X':
-                APPEND_FMT("%x", (unsigned int) now);
-                break;
-              case 'Y':       /* this will break in the year 10000 ;-) */
-                APPEND_FMT("%04d", tm->tm_year + 1900);
-                break;
-              case '%':
-                APPEND_BYTE('%');
-                break;
-              default:       /* invalid formats are replaced by '.' */
-                APPEND_BYTE('.');
-                m_strncat(buf, len, ".", 1); 
-            }
-            ++fmt;
-        } else {
-            APPEND_BYTE(mutt_normalized_char(*fmt));
+        switch (*fmt++) {
+          case 0:
+            return;
+          case 'd':
+            APPEND_FMT("%02d", tm->tm_mday);
+            break;
+          case 'h':
+            APPEND_FMT("%02d", tm->tm_hour);
+            break;
+          case 'm':
+            APPEND_FMT("%02d", tm->tm_mon + 1);
+            break;
+          case 'M':
+            APPEND_FMT("%02d", tm->tm_min);
+            break;
+          case 'O':
+            APPEND_FMT("%lo", (unsigned long)now);
+            break;
+          case 'p':
+            APPEND_FMT("%u", (unsigned int)getpid());
+            break;
+          case 'P':
+            APPEND_FMT("%c", MsgIdPfx);
+            MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1;
+            break;
+          case 'r':
+            APPEND_FMT("%u", (unsigned int)rand());
+            break;
+          case 'R':
+            APPEND_FMT("%x", (unsigned int)rand());
+            break;
+          case 's':
+            APPEND_FMT("%02d", tm->tm_sec);
+            break;
+          case 'T':
+            APPEND_FMT("%u", (unsigned int) now);
+            break;
+          case 'X':
+            APPEND_FMT("%x", (unsigned int) now);
+            break;
+          case 'Y':       /* this will break in the year 10000 ;-) */
+            APPEND_FMT("%04d", tm->tm_year + 1900);
+            break;
+          case '%':
+            APPEND_BYTE('%');
+            break;
+          default:       /* invalid formats are replaced by '.' */
+            APPEND_BYTE('.');
+            m_strncat(buf, len, ".", 1); 
         }
         }
+    }
+
+    *buf = '\0';
 
 #undef APPEND_BYTE
 #undef APPEND_FMT
 
 #undef APPEND_BYTE
 #undef APPEND_FMT
-    }
 }
 
 char *mutt_gen_msgid (void)
 }
 
 char *mutt_gen_msgid (void)