]> diplodocus.org Git - nmh/blobdiff - sbr/escape_addresses.c
new.c: Order two return statements to match comment.
[nmh] / sbr / escape_addresses.c
index a7dc14672852748d2456071f97fa7617e1a1fc2e..05c6f9365def246518e07e8404a1f5ac8611460d 100644 (file)
@@ -1,18 +1,14 @@
-/*
- * escape_addresses.c -- Escape address components, hopefully per RFC 5322.
+/* escape_addresses.c -- Escape address components, hopefully per RFC 5322.
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
-#include <sys/types.h>
+#include <h/mh.h>
 #include <h/utils.h>
 #include <h/utils.h>
-#include <string.h>
-#include <stdlib.h>
 
 
-static void
-escape_component (char *name, size_t namesize, char *chars);
+static void escape_component (char *name, size_t namesize, char *chars);
 
 
 void
 
 
 void
@@ -36,7 +32,7 @@ escape_local_part (char *name, size_t namesize) {
    argument is modified in place.  Its size is specified by the
    namesize argument.  The need_escape argument is a string of
    characters that require that name be escaped. */
    argument is modified in place.  Its size is specified by the
    namesize argument.  The need_escape argument is a string of
    characters that require that name be escaped. */
-void
+static void
 escape_component (char *name, size_t namesize, char *chars_to_escape) {
     /* If name contains any chars_to_escape:
        1) enclose it in ""
 escape_component (char *name, size_t namesize, char *chars_to_escape) {
     /* If name contains any chars_to_escape:
        1) enclose it in ""
@@ -45,7 +41,7 @@ escape_component (char *name, size_t namesize, char *chars_to_escape) {
     if (strpbrk(name, chars_to_escape)) {
         char *destp, *srcp;
         /* Maximum space requirement would be if each character had
     if (strpbrk(name, chars_to_escape)) {
         char *destp, *srcp;
         /* Maximum space requirement would be if each character had
-           to be escaped, plus enclosing double quotes, plus null termintor.
+           to be escaped, plus enclosing double quotes, plus NUL terminator.
            E.g., 2 characters, "", would require 7, "\"\""0, where that 0
            is '\0'. */
         char *tmp = mh_xmalloc (2*strlen(name) + 3);
            E.g., 2 characters, "", would require 7, "\"\""0, where that 0
            is '\0'. */
         char *tmp = mh_xmalloc (2*strlen(name) + 3);
@@ -77,9 +73,9 @@ escape_component (char *name, size_t namesize, char *chars_to_escape) {
         }
 
         if (strcmp (tmp, "\"")) {
         }
 
         if (strcmp (tmp, "\"")) {
-            /* assert (strlen(tmp) + 1 == destp - tmp); */
             size_t len = destp - tmp;
             size_t len = destp - tmp;
-            strncpy (name, tmp, len <= namesize  ?  len  :  namesize);
+            assert ((ssize_t) strlen(tmp) + 1 == destp - tmp);
+            strncpy (name, tmp, min(len, namesize));
         } else {
             /* Handle just " as special case here instead of above. */
             strncpy (name, "\"\\\"\"", namesize);
         } else {
             /* Handle just " as special case here instead of above. */
             strncpy (name, "\"\\\"\"", namesize);