[Pkg-gnupg-commit] [gnupg2] 172/185: gpg: Minor rework for better readibility of get_best_pubkey_byname.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Aug 7 11:55:33 UTC 2017


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

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 1c35e29af95c46475f297d2bd70a5f3bd49d45b1
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Jul 28 11:08:32 2017 +0200

    gpg: Minor rework for better readibility of get_best_pubkey_byname.
    
    * g10/getkey.c (get_best_pubkey_byname): Change return type to
    gpg_error_t.  Use var name err instead of rc.  Move a
    gpg_error_from_syserror closer to the call.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 g10/getkey.c | 26 +++++++++++++-------------
 g10/keydb.h  |  8 ++++----
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/g10/getkey.c b/g10/getkey.c
index e0c4bd9..79bce61 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1583,24 +1583,23 @@ pubkey_cmp (ctrl_t ctrl, const char *name, struct pubkey_cmp_cookie *old,
 /* This function works like get_pubkey_byname, but if the name
  * resembles a mail address, the results are ranked and only the best
  * result is returned.  */
-int
+gpg_error_t
 get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
                         const char *name, KBNODE *ret_keyblock,
                         int include_unusable, int no_akl)
 {
-  int rc;
+  gpg_error_t err;
   struct getkey_ctx_s *ctx = NULL;
 
   if (retctx)
     *retctx = NULL;
 
-  rc = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock,
-                          NULL, include_unusable, no_akl);
-  if (rc)
+  err = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock,
+                           NULL, include_unusable, no_akl);
+  if (err)
     {
-      if (ctx)
-        getkey_end (ctrl, ctx);
-      return rc;
+      getkey_end (ctrl, ctx);
+      return err;
     }
 
   if (is_valid_mailbox (name) && ctx)
@@ -1647,16 +1646,17 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
             {
               ctx = xtrycalloc (1, sizeof **retctx);
               if (! ctx)
-                rc = gpg_error_from_syserror ();
+                err = gpg_error_from_syserror ();
               else
                 {
                   ctx->kr_handle = keydb_new ();
                   if (! ctx->kr_handle)
                     {
+                      err = gpg_error_from_syserror ();
                       xfree (ctx);
+                      ctx = NULL;
                       if (retctx)
                         *retctx = NULL;
-                      rc = gpg_error_from_syserror ();
                     }
                   else
                     {
@@ -1671,7 +1671,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
                         {
                           release_kbnode (*ret_keyblock);
                           *ret_keyblock = NULL;
-                          rc = getkey_next (ctrl, ctx, NULL, ret_keyblock);
+                          err = getkey_next (ctrl, ctx, NULL, ret_keyblock);
                         }
                     }
                 }
@@ -1684,7 +1684,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
         }
     }
 
-  if (rc && ctx)
+  if (err && ctx)
     {
       getkey_end (ctrl, ctx);
       ctx = NULL;
@@ -1695,7 +1695,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
   else
     getkey_end (ctrl, ctx);
 
-  return rc;
+  return err;
 }
 
 

diff --git a/g10/keydb.h b/g10/keydb.h
index 15345bb..f793ada 100644
--- a/g10/keydb.h
+++ b/g10/keydb.h
@@ -319,10 +319,10 @@ int get_pubkey_byname (ctrl_t ctrl,
 
 /* Likewise, but only return the best match if NAME resembles a mail
  * address.  */
-int get_best_pubkey_byname (ctrl_t ctrl,
-			    GETKEY_CTX *retctx, PKT_public_key *pk,
-			    const char *name, KBNODE *ret_keyblock,
-			    int include_unusable, int no_akl);
+gpg_error_t get_best_pubkey_byname (ctrl_t ctrl,
+                                    GETKEY_CTX *retctx, PKT_public_key *pk,
+                                    const char *name, KBNODE *ret_keyblock,
+                                    int include_unusable, int no_akl);
 
 /* Get a public key directly from file FNAME.  */
 gpg_error_t get_pubkey_fromfile (ctrl_t ctrl,

-- 
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