make some code yet more simple, using the VERY good semantics of snprintf
[apps/madmutt.git] / lib-mime / rfc822address.c
index 190588c..ad4e117 100644 (file)
@@ -396,15 +396,9 @@ ssize_t rfc822_write_address_single(char *buf, ssize_t buflen,
     if (!addr)
         return 0;
 
     if (!addr)
         return 0;
 
-    buflen--;                     /* save room for the terminal nul */
-
     if (addr->personal) {
         pos = rfc822_strcpy(buf, buflen, addr->personal, RFC822Specials);
     if (addr->personal) {
         pos = rfc822_strcpy(buf, buflen, addr->personal, RFC822Specials);
-        if (pos + 2 >= buflen)
-            goto done;
-
-        buf[pos++] = ' ';
-        buf[pos++] = '<';
+        pos += m_strcpy(buf + pos, buflen - pos, " <");
     }
 
     if (addr->mailbox) {
     }
 
     if (addr->mailbox) {
@@ -415,26 +409,16 @@ ssize_t rfc822_write_address_single(char *buf, ssize_t buflen,
         }
 
         if (addr->personal) {
         }
 
         if (addr->personal) {
-            if (pos + 1 >= buflen)
-                goto done;
-            buf[pos++] = '>';
+            pos += m_strcpy(buf + pos, buflen - pos, ">");
         }
 
         if (addr->group) {
         }
 
         if (addr->group) {
-            if (pos + 1 >= buflen)
-                goto done;
-            buf[pos++] = ':';
+            pos += m_strcpy(buf + pos, buflen - pos, ":");
         }
     } else {
         }
     } else {
-        if (pos + 1 >= buflen)
-            goto done;
-        buf[pos++] = ';';
+        pos += m_strcpy(buf + pos, buflen - pos, ";");
     }
 
     }
 
-  done:
-    /* no need to check for length here since we already save space at the
-       beginning of this routine */
-    buf[pos] = 0;
     return pos;
 }
 
     return pos;
 }
 
@@ -444,34 +428,23 @@ rfc822_write_address(char *buf, ssize_t buflen, address_t *addr, int display)
 {
     ssize_t pos;
 
 {
     ssize_t pos;
 
-    buflen--;                     /* save room for the terminal nul */
     pos = m_strnlen(buf, buflen);
 
     if (pos) {
     pos = m_strnlen(buf, buflen);
 
     if (pos) {
-        if (pos + 2 >= buflen)
-            goto done;
-
-        buf[pos++] = ',';
-        buf[pos++] = ' ';
+        pos += m_strcpy(buf + pos, buflen - pos, ", ");
     }
 
     for (; addr; addr = addr->next) {
     }
 
     for (; addr; addr = addr->next) {
-        pos += rfc822_write_address_single(buf + pos, buflen + 1 - pos,
+        pos += rfc822_write_address_single(buf + pos, buflen - pos,
                                            addr, display);
 
         if (!addr->group && addr->next && addr->next->mailbox) {
             /* if there is another address, and its not a group mailbox name or
                group terminator, add a comma to separate the addresses */
                                            addr, display);
 
         if (!addr->group && addr->next && addr->next->mailbox) {
             /* if there is another address, and its not a group mailbox name or
                group terminator, add a comma to separate the addresses */
-            if (pos + 2 >= buflen)
-                break;
-
-            buf[pos++] = ',';
-            buf[pos++] = ' ';
+            pos += m_strcpy(buf + pos, buflen - pos, ", ");
         }
     }
 
         }
     }
 
-  done:
-    buf[pos] = '\0';
     return pos;
 }
 
     return pos;
 }