[Pkg-gnupg-commit] [gnupg2] 26/102: gpgtar: Simplify code by using ccparray.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Jun 17 00:14:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 91bc7833836f19256d56984c94cacf44853ff5c8
Author: Werner Koch <wk at gnupg.org>
Date:   Tue May 24 15:54:48 2016 +0200

    gpgtar: Simplify code by using ccparray.
    
    * tools/gpgtar-create.c (gpgtar_create): Use ccparray functions.
    * tools/gpgtar-extract.c (gpgtar_extract): Ditto.
    * tools/gpgtar-list.c (gpgtar_list): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 tools/gpgtar-create.c  | 50 ++++++++++++++++++++++----------------------------
 tools/gpgtar-extract.c | 21 +++++++++++----------
 tools/gpgtar-list.c    | 21 +++++++++++----------
 3 files changed, 44 insertions(+), 48 deletions(-)

diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c
index 968dca6..f7c8b1a 100644
--- a/tools/gpgtar-create.c
+++ b/tools/gpgtar-create.c
@@ -38,6 +38,7 @@
 #include "i18n.h"
 #include "../common/exectool.h"
 #include "../common/sysutils.h"
+#include "../common/ccparray.h"
 #include "gpgtar.h"
 
 #ifndef HAVE_LSTAT
@@ -888,8 +889,8 @@ gpgtar_create (char **inpattern, int encrypt, int sign)
 
   if (encrypt || sign)
     {
-      int i;
       strlist_t arg;
+      ccparray_t ccp;
       const char **argv;
 
       err = es_fseek (outstream, 0, SEEK_SET);
@@ -899,43 +900,36 @@ gpgtar_create (char **inpattern, int encrypt, int sign)
       /* '--encrypt' may be combined with '--symmetric', but 'encrypt'
          is set either way.  Clear it if no recipients are specified.
          XXX: Fix command handling.  */
-       if (opt.symmetric && opt.recipients == NULL)
-         encrypt = 0;
-
-      argv = xtrycalloc (strlist_length (opt.gpg_arguments)
-                         + 2 * strlist_length (opt.recipients)
-                         + 1 + !!encrypt + !!sign + 2 * !!opt.user
-                         + !!opt.symmetric,
-                         sizeof *argv);
-      if (argv == NULL)
-        {
-          err = gpg_error_from_syserror ();
-          goto leave;
-        }
-      i = 0;
+      if (opt.symmetric && opt.recipients == NULL)
+        encrypt = 0;
+
+      ccparray_init (&ccp, 0);
       if (encrypt)
-        argv[i++] = "--encrypt";
+        ccparray_put (&ccp, "--encrypt");
       if (sign)
-        argv[i++] = "--sign";
+        ccparray_put (&ccp, "--sign");
       if (opt.user)
         {
-          argv[i++] = "--local-user";
-          argv[i++] = opt.user;
+          ccparray_put (&ccp, "--local-user");
+          ccparray_put (&ccp, opt.user);
         }
       if (opt.symmetric)
-        argv[i++] = "--symmetric";
+        ccparray_put (&ccp, "--symmetric");
       for (arg = opt.recipients; arg; arg = arg->next)
         {
-          argv[i++] = "--recipient";
-          argv[i++] = arg->d;
+          ccparray_put (&ccp, "--recipient");
+          ccparray_put (&ccp, arg->d);
         }
       for (arg = opt.gpg_arguments; arg; arg = arg->next)
-        argv[i++] = arg->d;
-      argv[i++] = NULL;
-      assert (i == strlist_length (opt.gpg_arguments)
-              + 2 * strlist_length (opt.recipients)
-              + 1 + !!encrypt + !!sign + 2 * !!opt.user
-              + !!opt.symmetric);
+        ccparray_put (&ccp, arg->d);
+
+      ccparray_put (&ccp, NULL);
+      argv = ccparray_get (&ccp, NULL);
+      if (!argv)
+        {
+          err = gpg_error_from_syserror ();
+          goto leave;
+        }
 
       err = gnupg_exec_tool_stream (opt.gpg_program, argv,
                                     outstream, cipher_stream);
diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c
index 95f2b56..3ee73ef 100644
--- a/tools/gpgtar-extract.c
+++ b/tools/gpgtar-extract.c
@@ -30,6 +30,7 @@
 #include "i18n.h"
 #include "../common/exectool.h"
 #include "../common/sysutils.h"
+#include "../common/ccparray.h"
 #include "gpgtar.h"
 
 
@@ -299,8 +300,8 @@ gpgtar_extract (const char *filename, int decrypt)
 
   if (decrypt)
     {
-      int i;
       strlist_t arg;
+      ccparray_t ccp;
       const char **argv;
 
       cipher_stream = stream;
@@ -311,19 +312,19 @@ gpgtar_extract (const char *filename, int decrypt)
           goto leave;
         }
 
-      argv = xtrycalloc (strlist_length (opt.gpg_arguments) + 2,
-                         sizeof *argv);
-      if (argv == NULL)
+      ccparray_init (&ccp, 0);
+
+      ccparray_put (&ccp, "--decrypt");
+      for (arg = opt.gpg_arguments; arg; arg = arg->next)
+        ccparray_put (&ccp, arg->d);
+
+      ccparray_put (&ccp, NULL);
+      argv = ccparray_get (&ccp, NULL);
+      if (!argv)
         {
           err = gpg_error_from_syserror ();
           goto leave;
         }
-      i = 0;
-      argv[i++] = "--decrypt";
-      for (arg = opt.gpg_arguments; arg; arg = arg->next)
-        argv[i++] = arg->d;
-      argv[i++] = NULL;
-      assert (i == strlist_length (opt.gpg_arguments) + 2);
 
       err = gnupg_exec_tool_stream (opt.gpg_program, argv,
                                     cipher_stream, stream);
diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c
index 25c70d2..930712a 100644
--- a/tools/gpgtar-list.c
+++ b/tools/gpgtar-list.c
@@ -27,6 +27,7 @@
 #include "i18n.h"
 #include "gpgtar.h"
 #include "../common/exectool.h"
+#include "../common/ccparray.h"
 
 
 

@@ -299,8 +300,8 @@ gpgtar_list (const char *filename, int decrypt)
 
   if (decrypt)
     {
-      int i;
       strlist_t arg;
+      ccparray_t ccp;
       const char **argv;
 
       cipher_stream = stream;
@@ -311,19 +312,19 @@ gpgtar_list (const char *filename, int decrypt)
           goto leave;
         }
 
-      argv = xtrycalloc (strlist_length (opt.gpg_arguments) + 2,
-                         sizeof *argv);
-      if (argv == NULL)
+      ccparray_init (&ccp, 0);
+
+      ccparray_put (&ccp, "--decrypt");
+      for (arg = opt.gpg_arguments; arg; arg = arg->next)
+        ccparray_put (&ccp, arg->d);
+
+      ccparray_put (&ccp, NULL);
+      argv = ccparray_get (&ccp, NULL);
+      if (!argv)
         {
           err = gpg_error_from_syserror ();
           goto leave;
         }
-      i = 0;
-      argv[i++] = "--decrypt";
-      for (arg = opt.gpg_arguments; arg; arg = arg->next)
-        argv[i++] = arg->d;
-      argv[i++] = NULL;
-      assert (i == strlist_length (opt.gpg_arguments) + 2);
 
       err = gnupg_exec_tool_stream (opt.gpg_program, argv,
                                     cipher_stream, stream);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list