]> granicus.if.org Git - neomutt/commitdiff
Convert pgp_invoke_list_keys and mix_send_message to use BUFFERs.
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Sep 2018 22:08:19 +0000 (15:08 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 1 Oct 2018 22:34:12 +0000 (23:34 +0100)
Both repetitively perform a lot of copying back in forth, which is
much cleaner with a BUFFER.

Note that in pgp_invoke_list_keys, if there are no hints uids->data
would be NULL.  However, the pgp_invoke() checks and wraps all the
format substitutions with NONULL.

ncrypt/pgpinvoke.c
remailer.c

index 4e0fb608adb64681386064eea061286c3660f230..bf05cfbe2c9d608ce10af2a51ffe7816b56166c5 100644 (file)
@@ -524,21 +524,27 @@ pid_t pgp_invoke_list_keys(FILE **pgpin, FILE **pgpout, FILE **pgperr,
                            int pgpinfd, int pgpoutfd, int pgperrfd,
                            enum PgpRing keyring, struct ListHead *hints)
 {
-  char uids[HUGE_STRING];
-  char tmpuids[HUGE_STRING];
+  struct Buffer *uids = NULL;
   char quoted[HUGE_STRING];
 
-  *uids = '\0';
+  pid_t rc;
+
+  uids = mutt_buffer_new();
+  mutt_buffer_increase_size(uids, HUGE_STRING);
 
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, hints, entries)
   {
     mutt_file_quote_filename((char *) np->data, quoted, sizeof(quoted));
-    snprintf(tmpuids, sizeof(tmpuids), "%s %s", uids, quoted);
-    strcpy(uids, tmpuids);
+    mutt_buffer_addstr(uids, quoted);
+    if (STAILQ_NEXT(np, entries))
+      mutt_buffer_addch(uids, ' ');
   }
 
-  return pgp_invoke(pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, false,
-                    NULL, NULL, uids,
-                    keyring == PGP_SECRING ? PgpListSecringCommand : PgpListPubringCommand);
+  rc = pgp_invoke(pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, 0, NULL,
+                  NULL, uids->data,
+                  keyring == PGP_SECRING ? PgpListSecringCommand : PgpListPubringCommand);
+
+  mutt_buffer_free(&uids);
+  return rc;
 }
index f992ac212b69a899cbf4add1be27d9b79eef0ec5..a3d7170a22961976b68859367b7e552e6b0950e1 100644 (file)
@@ -820,25 +820,26 @@ int mix_check_message(struct Email *msg)
  */
 int mix_send_message(struct ListHead *chain, const char *tempfile)
 {
-  char cmd[HUGE_STRING];
-  char tmp[HUGE_STRING];
+  struct Buffer *cmd = NULL;
   char cd_quoted[STRING];
-  int i;
+  int i = 0;
 
-  snprintf(cmd, sizeof(cmd), "cat %s | %s -m ", tempfile, Mixmaster);
+  cmd = mutt_buffer_new();
+  mutt_buffer_increase_size(cmd, HUGE_STRING);
+  mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, Mixmaster);
 
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, chain, entries)
   {
-    mutt_str_strfcpy(tmp, cmd, sizeof(tmp));
+    mutt_buffer_addstr(cmd, i ? "," : " -l ");
     mutt_file_quote_filename(np->data, cd_quoted, sizeof(cd_quoted));
-    snprintf(cmd, sizeof(cmd), "%s%s%s", tmp,
-             (np == STAILQ_FIRST(chain)) ? " -l " : ",", cd_quoted);
+    mutt_buffer_addstr(cmd, cd_quoted);
+    i = 1;
   }
 
   mutt_endwin();
 
-  i = mutt_system(cmd);
+  i = mutt_system(cmd->data);
   if (i != 0)
   {
     fprintf(stderr, _("Error sending message, child exited %d.\n"), i);
@@ -849,6 +850,7 @@ int mix_send_message(struct ListHead *chain, const char *tempfile)
     }
   }
 
+  mutt_buffer_free(&cmd);
   unlink(tempfile);
   return i;
 }