]> diplodocus.org Git - nmh/commitdiff
Use trim_suffix_c() to remove optional trailing character.
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 24 Jan 2018 00:12:59 +0000 (00:12 +0000)
committerRalph Corderoy <ralph@inputplus.co.uk>
Thu, 25 Jan 2018 14:44:44 +0000 (14:44 +0000)
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.

uip/mhlsbr.c
uip/sendsbr.c

index 86bae54..61bf796 100644 (file)
@@ -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]);
index f369f08..be3b414 100644 (file)
@@ -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);