From: Ralph Corderoy Date: Wed, 24 Jan 2018 00:12:59 +0000 (+0000) Subject: Use trim_suffix_c() to remove optional trailing character. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/ec7b66a6b21b391cf4ceaa0e38812c923f06cd94 Use trim_suffix_c() to remove optional trailing character. I'm unsure if one of the cases can know the string's length is long enough to read the char before the NUL. Using trim_suffix_c() simplifies and removes the possibility. --- diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 86bae544..61bf7965 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1837,7 +1837,7 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, switch (filterpid = fork()) { char **args, *program; struct arglist *a; - int i, dat[5], s, argp; + int i, dat[5], argp; case 0: /* @@ -1862,14 +1862,9 @@ filterbody (struct mcomp *c1, char *buf, int bufsz, int state, fmt_scan(a->a_fmt, scanl, BUFSIZ, dat, NULL); args[i] = charstring_buffer_copy (scanl); charstring_free (scanl); - /* - * fmt_scan likes to put a trailing newline at the end of the - * format string. If we have one, get rid of it. - */ - s = strlen(args[i]); - if (args[i][s - 1] == '\n') - args[i][s - 1] = '\0'; - + /* Trim a trailing linefeed that fmt_scan() likes to put at + * the end of the format string. */ + trim_suffix_c(args[i], '\n'); if (mhldebug) fprintf(stderr, "filterarg: fmt=\"%s\", output=\"%s\"\n", a->a_nfs, args[i]); diff --git a/uip/sendsbr.c b/uip/sendsbr.c index f369f08b..be3b414f 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -260,12 +260,8 @@ splitmsg (char **vec, int vecp, char *program, char *drft, * of each message/partial in the collection. */ if (!strcasecmp (name, "Subject")) { - size_t sublen; - strncpy (subject, buffer, BUFSIZ); - sublen = strlen (subject); - if (sublen > 0 && subject[sublen - 1] == '\n') - subject[sublen - 1] = '\0'; + trim_suffix_c(subject, '\n'); } dp = add (concat (name, ":", buffer, NULL), dp);