[git] GnuPG - branch, master, updated. gnupg-2.1.11-152-gb7fa496

by Werner Koch cvs at cvs.gnupg.org
Mon Apr 25 18:20:24 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  b7fa4960c292ef1a290d32b7f46bb741bbfc0923 (commit)
       via  2502a76d8edbca035fd2a1879f2132c36b51e2c1 (commit)
      from  8776abbe02935e720018f3ef6ffd48f21435ff8b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b7fa4960c292ef1a290d32b7f46bb741bbfc0923
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 25 18:14:12 2016 +0200

    common: Minor fixes for the new private-keys.c.
    
    * common/private-keys.c (my_error_from_syserror): New.  Use it in
    place of gpg_error_from_syserror.
    (_pkc_add, pkc_lookup, pke_next_value): Use ascii_strcasecmp.
    (pkc_parse): Use xtrystrdup and append_to_strlist_try as intended.
    
    (_pkc_add): Add braces around if-statement.
    --
    
    We should have a macro so that we do not need to define a wrapper
    function like my_error_from_syserror in files where it is needed.  I
    am not sure about a proper name, "my_" seems to be the easiest
    replacement.  Note that the global DEFAULT_ERRSOURCE is relatively new
    to replace the need to convey the error source in function calls; we
    want that function from common/ return the error source of the main
    binary.
    
    We require that a key is ASCII and thus we better use ascii_strcasecmp
    to avoid problems with strange locales.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/private-keys.c b/common/private-keys.c
index a3c06f9..4cf7d22 100644
--- a/common/private-keys.c
+++ b/common/private-keys.c
@@ -61,6 +61,15 @@ struct private_key_entry
   char *value;
 };
 
+
+/* Helper */
+static inline gpg_error_t
+my_error_from_syserror (void)
+{
+  return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
+}
+
+
 

 
 /* Allocation and deallocation.  */
@@ -179,7 +188,7 @@ assert_raw_value (pke_t entry)
 		&entry->value[offset]);
       if (append_to_strlist_try (&entry->raw_value, buf) == NULL)
 	{
-	  err = gpg_error_from_syserror ();
+	  err = my_error_from_syserror ();
 	  goto leave;
 	}
 
@@ -267,7 +276,7 @@ assert_value (pke_t entry)
 
   entry->value = p = xtrymalloc (len);
   if (entry->value == NULL)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   swallow_ws = 0;
   for (s = entry->raw_value; s; s = s->next)
@@ -326,7 +335,7 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
       goto leave;
     }
 
-  if (name && strcasecmp (name, "Key:") == 0 && pkc_lookup (pk, "Key:"))
+  if (name && ascii_strcasecmp (name, "Key:") == 0 && pkc_lookup (pk, "Key:"))
     {
       err = gpg_error (GPG_ERR_INV_NAME);
       goto leave;
@@ -335,7 +344,7 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
   e = xtrycalloc (1, sizeof *e);
   if (e == NULL)
     {
-      err = gpg_error_from_syserror ();
+      err = my_error_from_syserror ();
       goto leave;
     }
 
@@ -356,17 +365,18 @@ _pkc_add (pkc_t pk, char *name, char *value, strlist_t raw_value,
 
 	  /* If so, find the last in that block.  */
 	  if (last)
-	    while (last->next)
-	      {
-		pke_t next = last->next;
-
-		if (next->name && strcasecmp (next->name, name) == 0)
-		  last = next;
-		else
-		  break;
-	      }
-	  /* Otherwise, just find the last entry.  */
-	  else
+            {
+              while (last->next)
+                {
+                  pke_t next = last->next;
+
+                  if (next->name && ascii_strcasecmp (next->name, name) == 0)
+                    last = next;
+                  else
+                    break;
+                }
+            }
+	  else /* Otherwise, just find the last entry.  */
 	    last = pk->last;
 	}
 
@@ -410,13 +420,13 @@ pkc_add (pkc_t pk, const char *name, const char *value)
 
   k = xtrystrdup (name);
   if (k == NULL)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   v = xtrystrdup (value);
   if (v == NULL)
     {
       xfree (k);
-      return gpg_error_from_syserror ();
+      return my_error_from_syserror ();
     }
 
   return _pkc_add (pk, k, v, NULL, 0);
@@ -441,7 +451,7 @@ pkc_set (pkc_t pk, const char *name, const char *value)
 
       v = xtrystrdup (value);
       if (v == NULL)
-	return gpg_error_from_syserror ();
+	return my_error_from_syserror ();
 
       free_strlist_wipe (e->raw_value);
       e->raw_value = NULL;
@@ -496,7 +506,7 @@ pkc_lookup (pkc_t pk, const char *name)
 {
   pke_t entry;
   for (entry = pk->first; entry; entry = entry->next)
-    if (entry->name && strcasecmp (entry->name, name) == 0)
+    if (entry->name && ascii_strcasecmp (entry->name, name) == 0)
       return entry;
   return NULL;
 }
@@ -518,7 +528,7 @@ pke_t
 pke_next_value (pke_t entry, const char *name)
 {
   for (entry = entry->next; entry; entry = entry->next)
-    if (entry->name && strcasecmp (entry->name, name) == 0)
+    if (entry->name && ascii_strcasecmp (entry->name, name) == 0)
       return entry;
   return NULL;
 }
@@ -558,13 +568,13 @@ pkc_set_private_key (pkc_t pk, gcry_sexp_t sexp)
 
   raw = xtrymalloc (len);
   if (raw == NULL)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   clean = xtrymalloc (len);
   if (clean == NULL)
     {
       xfree (raw);
-      return gpg_error_from_syserror ();
+      return my_error_from_syserror ();
     }
 
   gcry_sexp_sprint (sexp, GCRYSEXP_FMT_ADVANCED, raw, len);
@@ -621,7 +631,7 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
 
   *result = pkc_new ();
   if (*result == NULL)
-    return gpg_error_from_syserror ();
+    return my_error_from_syserror ();
 
   if (errlinep)
     *errlinep = 0;
@@ -640,7 +650,7 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
 	  /* A continuation.  */
 	  if (append_to_strlist_try (&raw_value, buf) == NULL)
 	    {
-	      err = gpg_error_from_syserror ();
+	      err = my_error_from_syserror ();
 	      goto leave;
 	    }
 	  continue;
@@ -672,26 +682,26 @@ pkc_parse (pkc_t *result, int *errlinep, estream_t stream)
 	  value = colon + 1;
 	  tmp = *value;
 	  *value = 0;
-	  name = xstrdup (p);
+	  name = xtrystrdup (p);
 	  *value = tmp;
 
 	  if (name == NULL)
 	    {
-	      err = gpg_error_from_syserror ();
+	      err = my_error_from_syserror ();
 	      goto leave;
 	    }
 
-	  if (append_to_strlist (&raw_value, value) == NULL)
+	  if (append_to_strlist_try (&raw_value, value) == NULL)
 	    {
-	      err = gpg_error_from_syserror ();
+	      err = my_error_from_syserror ();
 	      goto leave;
 	    }
 	  continue;
 	}
 
-      if (append_to_strlist (&raw_value, buf) == NULL)
+      if (append_to_strlist_try (&raw_value, buf) == NULL)
 	{
-	  err = gpg_error_from_syserror ();
+	  err = my_error_from_syserror ();
 	  goto leave;
 	}
     }
@@ -733,7 +743,7 @@ pkc_write (pkc_t pk, estream_t stream)
 	es_fputs (s->d, stream);
 
       if (es_ferror (stream))
-	return gpg_error_from_syserror ();
+	return my_error_from_syserror ();
     }
 
   return 0;

commit 2502a76d8edbca035fd2a1879f2132c36b51e2c1
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 25 17:49:46 2016 +0200

    doc: Explain use of common error variable names.
    
    --

diff --git a/doc/HACKING b/doc/HACKING
index 11ae53b..d2168d6 100644
--- a/doc/HACKING
+++ b/doc/HACKING
@@ -74,7 +74,6 @@ do this after this scissor line:
 Note that such a comment will be removed if the git commit option
 =--cleanup=scissor= is used.
 
-
 ** License policy
 
   GnuPG is licensed under the GPLv3+ with some files under a mixed
@@ -131,12 +130,13 @@ Note that such a comment will be removed if the git commit option
   - Ignore signed/unsigned pointer mismatches
   - No arithmetic on void pointers; cast to char* first.
   - We use our own printf style functions like =es_printf=, and
-    =es_asprintf= which implement most C99 features with the exception
-    of =wchar_t= (which should anyway not be used).  Please always use
-    them and do not resort to those provided by libc.  The rationale
-    for using them is that we know that the format specifiers work on
-    all platforms and that we do not need to chase platform dependent
-    bugs.
+    =gpgrt_asprintf= (or the =es_asprintf= macro) which implement most
+    C99 features with the exception of =wchar_t= (which should anyway
+    not be used).  Please use them always and do not resort to those
+    provided by libc.  The rationale for using them is that we know
+    that the format specifiers work on all platforms and that we do
+    not need to chase platform dependent bugs.  Note also that in
+    gnupg asprintf is a macro already evaluating to gpgrt_asprintf.
   - It is common to have a label named "leave" for a function's
     cleanup and return code.  This helps with freeing memory and is a
     convenient location to set a breakpoint for debugging.
@@ -150,6 +150,23 @@ Note that such a comment will be removed if the git commit option
     end up in BSS.
   - Use --enable-maintainer-mode with configure.
 
+** Variable names
+
+  Follow the GNU standards.  Here are some conventions you may want to
+  stick to (do not rename existing "wrong" uses without a goog
+  reason).
+
+  - err :: This conveys an error code of type =gpg_error_t= which is
+           compatible to an =int=.  To compare such a variable to a
+           GPG_ERR_ constant, it is necessary to map the value like
+           this: =gpg_err_code(err)=.
+  - ec  :: This is used for a gpg-error code which has no source part
+           (=gpg_err_code_t=) and will eventually be used as input to
+           =gpg_err_make=.
+  - rc  :: Used for all kind of other errors; for example system
+           calls.  The value is not compatible with gpg-error.
+
+
 *** C99 language features
 
   In GnuPG 2.x, but *not in 1.4* and not in most libraries, a limited

-----------------------------------------------------------------------

Summary of changes:
 common/private-keys.c | 72 +++++++++++++++++++++++++++++----------------------
 doc/HACKING           | 31 +++++++++++++++++-----
 2 files changed, 65 insertions(+), 38 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list