[git] GnuPG - branch, neal/strsplit, updated. gnupg-2.1.2-28-gba2f59e

by Neal H. Walfield cvs at cvs.gnupg.org
Thu Mar 12 13:55:50 CET 2015


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, neal/strsplit has been updated
  discards  ba01f9aaa5a4f92cb1a27cefac3f7ae32b824759 (commit)
       via  ba2f59e3936c4d7bbb81f0f827c1552fa673faae (commit)
       via  e40636fefa7f9ded8216e3e55606ffc5c34cbce6 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (ba01f9aaa5a4f92cb1a27cefac3f7ae32b824759)
            \
             N -- N -- N (ba2f59e3936c4d7bbb81f0f827c1552fa673faae)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

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 ba2f59e3936c4d7bbb81f0f827c1552fa673faae
Author: Neal H. Walfield <neal at g10code.de>
Date:   Thu Mar 12 13:45:27 2015 +0100

    common:stringhelp.c: Replace use of jblib_malloc with xmalloc.
    
    --

diff --git a/common/stringhelp.c b/common/stringhelp.c
index 61386cc..7f40c7f 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -160,7 +160,7 @@ ascii_memistr ( const void *buffer, size_t buflen, const char *sub )
 /* This function is similar to strncpy().  However it won't copy more
    than N - 1 characters and makes sure that a '\0' is appended. With
    N given as 0, nothing will happen.  With DEST given as NULL, memory
-   will be allocated using jnlib_xmalloc (i.e. if it runs out of core
+   will be allocated using xmalloc (i.e. if it runs out of core
    the function terminates).  Returns DES or a pointer to the
    allocated memory.
  */
@@ -172,7 +172,7 @@ mem2str( char *dest , const void *src , size_t n )
 
     if( n ) {
 	if( !dest )
-	    dest = jnlib_xmalloc( n ) ;
+	    dest = xmalloc( n ) ;
 	d = dest;
 	s = src ;
 	for(n--; n && *s; n-- )
@@ -320,10 +320,10 @@ make_basename(const char *filepath, const char *inputpath)
 	    if ( !(p=strrchr(filepath, ':')) )
 #endif
 	      {
-		return jnlib_xstrdup(filepath);
+		return xstrdup(filepath);
 	      }
 
-    return jnlib_xstrdup(p+1);
+    return xstrdup(p+1);
 #endif
 }
 
@@ -349,11 +349,11 @@ make_dirname(const char *filepath)
 	    if ( !(p=strrchr(filepath, ':')) )
 #endif
 	      {
-		return jnlib_xstrdup(".");
+		return xstrdup(".");
 	      }
 
     dirname_length = p-filepath;
-    dirname = jnlib_xmalloc(dirname_length+1);
+    dirname = xmalloc(dirname_length+1);
     strncpy(dirname, filepath, dirname_length);
     dirname[dirname_length] = 0;
 
@@ -386,9 +386,9 @@ get_pwdir (int xmode, const char *name)
   if (pwd)
     {
       if (xmode)
-        result = jnlib_xstrdup (pwd->pw_dir);
+        result = xstrdup (pwd->pw_dir);
       else
-        result = jnlib_strdup (pwd->pw_dir);
+        result = xtrystrdup (pwd->pw_dir);
     }
 #else /*!HAVE_PWD_H*/
   /* No support at all.  */
@@ -452,10 +452,10 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
           char *user;
 
           if (xmode)
-            user = jnlib_xstrdup (first_part+1);
+            user = xstrdup (first_part+1);
           else
             {
-              user = jnlib_strdup (first_part+1);
+              user = xtrystrdup (first_part+1);
               if (!user)
                 return NULL;
             }
@@ -465,7 +465,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
           skip = 1 + strlen (user);
 
           home = home_buffer = get_pwdir (xmode, user);
-          jnlib_free (user);
+          xfree (user);
           if (home)
             n += strlen (home);
           else
@@ -474,13 +474,13 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
     }
 
   if (xmode)
-    name = jnlib_xmalloc (n);
+    name = xmalloc (n);
   else
     {
-      name = jnlib_malloc (n);
+      name = xtrymalloc (n);
       if (!name)
         {
-          jnlib_free (home_buffer);
+          xfree (home_buffer);
           return NULL;
         }
     }
@@ -490,7 +490,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
   else
     p = stpcpy (name, first_part);
 
-  jnlib_free (home_buffer);
+  xfree (home_buffer);
   for (argc=0; argv[argc]; argc++)
     p = stpcpy (stpcpy (p, "/"), argv[argc]);
 
@@ -520,18 +520,18 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
                            strerror (errno));
                   exit(2);
                 }
-              jnlib_free (name);
+              xfree (name);
               return NULL;
             }
           n = strlen (home) + 1 + strlen (name) + 1;
           if (xmode)
-            home_buffer = jnlib_xmalloc (n);
+            home_buffer = xmalloc (n);
           else
             {
-              home_buffer = jnlib_malloc (n);
+              home_buffer = xtrymalloc (n);
               if (!home_buffer)
                 {
-                  jnlib_free (name);
+                  xfree (name);
                   return NULL;
                 }
             }
@@ -543,7 +543,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
               p = home_buffer + (p - name + 1);
             }
           strcpy (stpcpy (stpcpy (p, home), "/"), name);
-          jnlib_free (name);
+          xfree (name);
           name = home_buffer;
           /* Let's do a simple compression to catch the most common
              case of using "." for gpg's --homedir option.  */
@@ -701,7 +701,7 @@ sanitize_buffer (const void *p_arg, size_t n, int delim)
   p = save_p;
   n = save_n;
   /* And now make the string */
-  d = buffer = jnlib_xmalloc( buflen );
+  d = buffer = xmalloc( buflen );
   for ( ; n; n--, p++ )
     {
       if (*p < 0x20 || *p == 0x7f || *p == delim || (delim && *p=='\\')) {
@@ -1064,10 +1064,10 @@ do_percent_escape (const char *str, const char *extra, int die)
     if (str[i] == ':' || str[i] == '%' || (extra && strchr (extra, str[i])))
       j++;
   if (die)
-    ptr = jnlib_xmalloc (i + 2 * j + 1);
+    ptr = xmalloc (i + 2 * j + 1);
   else
     {
-      ptr = jnlib_malloc (i + 2 * j + 1);
+      ptr = xtrymalloc (i + 2 * j + 1);
       if (!ptr)
         return NULL;
     }
@@ -1142,7 +1142,7 @@ do_strconcat (const char *s1, va_list arg_ptr)
       argc++;
     }
   needed++;
-  buffer = jnlib_malloc (needed);
+  buffer = xtrymalloc (needed);
   if (buffer)
     {
       for (p = buffer, argc=0; argv[argc]; argc++)
@@ -1162,7 +1162,7 @@ strconcat (const char *s1, ...)
   char *result;
 
   if (!s1)
-    result = jnlib_strdup ("");
+    result = xtrystrdup ("");
   else
     {
       va_start (arg_ptr, s1);
@@ -1181,7 +1181,7 @@ xstrconcat (const char *s1, ...)
   char *result;
 
   if (!s1)
-    result = jnlib_xstrdup ("");
+    result = xstrdup ("");
   else
     {
       va_start (arg_ptr, s1);

commit e40636fefa7f9ded8216e3e55606ffc5c34cbce6
Author: Neal H. Walfield <neal at g10code.de>
Date:   Thu Mar 12 13:03:50 2015 +0100

    common: Add new helper function, strsplit.
    
    * common/stringhelp.h (strsplit): New declaration.
    * common/stringhelp.c (strsplit): New function.
    * common/t-stringhelp.c (test_strsplit): New function.
    (main): Call it here.
    
    --

diff --git a/common/stringhelp.c b/common/stringhelp.c
index 42e1bcb..61386cc 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -2,6 +2,7 @@
  * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
  *               2008, 2009, 2010  Free Software Foundation, Inc.
  * Copyright (C) 2014 Werner Koch
+ * Copyright (C) 2015  g10 Code GmbH
  *
  * This file is part of JNLIB, which is a subsystem of GnuPG.
  *
@@ -48,6 +49,7 @@
 # include <windows.h>
 #endif
 
+#include "util.h"
 #include "libjnlib-config.h"
 #include "utf8conv.h"
 #include "sysutils.h"
@@ -1196,3 +1198,39 @@ xstrconcat (const char *s1, ...)
     }
   return result;
 }
+
+/* Split a string into fields at DELIM.  REPLACEMENT is the character
+   to replace the delimiter with (normally: '\0' so that each field is
+   NUL terminated).  The caller is responsible for freeing the result.
+   Note: this function modifies STRING!  If you need the original
+   value, then you should pass a copy to this function.
+
+   If malloc fails, this function returns NULL.  */
+char **
+strsplit (char *string, char delim, char replacement, int *count)
+{
+  int fields = 1;
+  char *t;
+  char **result;
+
+  /* First, count the number of fields.  */
+  for (t = strchr (string, delim); t; t = strchr (t + 1, delim))
+    fields ++;
+
+  result = xtrycalloc (sizeof (*result), (fields + 1));
+  if (! result)
+    return NULL;
+
+  result[0] = string;
+  fields = 1;
+  for (t = strchr (string, delim); t; t = strchr (t + 1, delim))
+    {
+      result[fields ++] = t + 1;
+      *t = replacement;
+    }
+
+  if (count)
+    *count = fields;
+
+  return result;
+}
diff --git a/common/stringhelp.h b/common/stringhelp.h
index ffef2d5..864a689 100644
--- a/common/stringhelp.h
+++ b/common/stringhelp.h
@@ -1,6 +1,7 @@
 /* stringhelp.h
  * Copyright (C) 1998, 1999, 2000, 2001, 2003,
  *               2006, 2007, 2009  Free Software Foundation, Inc.
+ *               2015  g10 Code GmbH
  *
  * This file is part of JNLIB, which is a subsystem of GnuPG.
  *
@@ -142,9 +143,9 @@ char *strconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
 /* Ditto, but die on error.  */
 char *xstrconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
 
+char **strsplit (char *string, char delim, char replacement, int *count);
 
 /*-- mapstrings.c --*/
 const char *map_static_macro_string (const char *string);
 
-
 #endif /*LIBJNLIB_STRINGHELP_H*/
diff --git a/common/t-stringhelp.c b/common/t-stringhelp.c
index dcd5a45..f5b6cd9 100644
--- a/common/t-stringhelp.c
+++ b/common/t-stringhelp.c
@@ -1,5 +1,6 @@
 /* t-stringhelp.c - Regression tests for stringhelp.c
  * Copyright (C) 2007 Free Software Foundation, Inc.
+ *               2015  g10 Code GmbH
  *
  * This file is part of JNLIB, which is a subsystem of GnuPG.
  *
@@ -478,6 +479,62 @@ test_make_absfilename_try (void)
   xfree (cwd);
 }
 
+static void
+test_strsplit (void)
+{
+  int test_count = 0;
+  void test (const char *s, char delim, char replacement,
+	     const char *fields_expected[])
+  {
+    char *s2;
+    int field_count;
+    char **fields;
+    int field_count_expected;
+    int i;
+
+    /* Count the fields.  */
+    for (field_count_expected = 0;
+	 fields_expected[field_count_expected];
+	 field_count_expected ++)
+      ;
+
+    test_count ++;
+
+    /* We need to copy s since strsplit modifies it in place.  */
+    s2 = xstrdup (s);
+    fields = strsplit (s2, delim, replacement, &field_count);
+
+    if (field_count != field_count_expected)
+      fail (test_count * 1000);
+
+    for (i = 0; i < field_count_expected; i ++)
+      if (strcmp (fields_expected[i], fields[i]) != 0)
+	{
+	  printf ("For field %d, expected '%s', but got '%s'\n",
+		  i, fields_expected[i], fields[i]);
+	  fail (test_count * 1000 + i + 1);
+	}
+
+    xfree (s2);
+  }
+
+  {
+    const char *expected_result[] =
+      { "a", "bc", "cde", "fghi", "jklmn", "", "foo", "", NULL };
+    test ("a:bc:cde:fghi:jklmn::foo:", ':', '\0', expected_result);
+  }
+
+  {
+    const char *expected_result[] =
+      { "!a!bc!!def!", "a!bc!!def!", "bc!!def!", "!def!", "def!", "", NULL };
+    test (",a,bc,,def,", ',', '!', expected_result);
+  }
+
+  {
+    const char *expected_result[] = { "", NULL };
+    test ("", ':', ',', expected_result);
+  }
+}
 
 int
 main (int argc, char **argv)
@@ -491,6 +548,7 @@ main (int argc, char **argv)
   test_xstrconcat ();
   test_make_filename_try ();
   test_make_absfilename_try ();
+  test_strsplit ();
 
   xfree (home_buffer);
   return 0;

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

Summary of changes:
 common/stringhelp.c | 57 +++++++++++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 28 deletions(-)


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




More information about the Gnupg-commits mailing list