*
* 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.
*/
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. */
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 ""
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
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);
- 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);