[SCM] Samba Shared Repository - branch master updated
Volker Lendecke
vlendec at samba.org
Mon Feb 29 14:19:02 UTC 2016
The branch, master has been updated
via 7105e171 lib/util: Add tests for strv_addn()
via 0133ed4 lib/util: Add strv_addn()
via 049e47b Revert "lib/util: Expose strv_addn() for adding string with specified length"
from abd8b18 smbd:smb2_creat: remove outdated TODO comments
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 7105e171f0f746da306c9f221e9558cacf8cd02d
Author: Martin Schwenke <martin at meltin.net>
Date: Mon Feb 29 20:04:19 2016 +1100
lib/util: Add tests for strv_addn()
Also some other minor test cleanups.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Reviewed-by: Volker Lendecke <vl at samba.org>
Autobuild-User(master): Volker Lendecke <vl at samba.org>
Autobuild-Date(master): Mon Feb 29 15:18:17 CET 2016 on sn-devel-144
commit 0133ed4c2235264882d1a110d631a71042533a19
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 29 15:15:04 2016 +1100
lib/util: Add strv_addn()
strv_addn() adds some number of characters from an existing string.
This is useful for parsing.
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 049e47b4434c745f650dcf6b599eaf886c95c506
Author: Martin Schwenke <martin at meltin.net>
Date: Mon Feb 29 19:49:39 2016 +1100
Revert "lib/util: Expose strv_addn() for adding string with specified length"
This reverts commit 0c61dd15137b4603bd47b3d6ae18ded6bd18ffae.
The intention of strv_addn() is to be able to add some number of
characters from an existing string. This implementation carelessly
assumes that the old _strv_append() added the trailing NUL to form a
valid strv. That's not true.
New implementation to follow.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Reviewed-by: Volker Lendecke <vl at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/util/strv.c | 16 +++++++++++++---
lib/util/strv.h | 2 +-
lib/util/tests/strv.c | 36 ++++++++++++++++++++++++++++++++++--
3 files changed, 48 insertions(+), 6 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/util/strv.c b/lib/util/strv.c
index fab3e56..577cd4d 100644
--- a/lib/util/strv.c
+++ b/lib/util/strv.c
@@ -22,7 +22,8 @@
#include "talloc.h"
#include <string.h>
-int strv_addn(TALLOC_CTX *mem_ctx, char **dst, const char *src, size_t srclen)
+static int _strv_append(TALLOC_CTX *mem_ctx, char **dst, const char *src,
+ size_t srclen)
{
size_t dstlen = talloc_array_length(*dst);
size_t newlen = dstlen + srclen;
@@ -44,12 +45,21 @@ int strv_addn(TALLOC_CTX *mem_ctx, char **dst, const char *src, size_t srclen)
int strv_add(TALLOC_CTX *mem_ctx, char **strv, const char *string)
{
- return strv_addn(mem_ctx, strv, string, strlen(string)+1);
+ return _strv_append(mem_ctx, strv, string, strlen(string)+1);
+}
+
+int strv_addn(TALLOC_CTX *mem_ctx, char **strv, const char *string, size_t n)
+{
+ char t[n+1];
+
+ memcpy(t, string, n);
+ t[n] = '\0';
+ return _strv_append(mem_ctx, strv, t, n+1);
}
int strv_append(TALLOC_CTX *mem_ctx, char **strv, const char *src)
{
- return strv_addn(mem_ctx, strv, src, talloc_array_length(src));
+ return _strv_append(mem_ctx, strv, src, talloc_array_length(src));
}
static bool strv_valid_entry(const char *strv, const char *entry,
diff --git a/lib/util/strv.h b/lib/util/strv.h
index fb1a806..a3fe7ab 100644
--- a/lib/util/strv.h
+++ b/lib/util/strv.h
@@ -23,7 +23,7 @@
#include "talloc.h"
int strv_add(TALLOC_CTX *mem_ctx, char **strv, const char *string);
-int strv_addn(TALLOC_CTX *mem_ctx, char **dst, const char *src, size_t srclen);
+int strv_addn(TALLOC_CTX *mem_ctx, char **strv, const char *src, size_t srclen);
int strv_append(TALLOC_CTX *mem_ctx, char **strv, const char *src);
char *strv_next(char *strv, const char *entry);
char *strv_find(char *strv, const char *entry);
diff --git a/lib/util/tests/strv.c b/lib/util/tests/strv.c
index 4030c44..c79ed5c 100644
--- a/lib/util/tests/strv.c
+++ b/lib/util/tests/strv.c
@@ -85,11 +85,11 @@ static bool test_strv_single(struct torture_context *tctx)
static bool test_strv_multi(struct torture_context *tctx)
{
- const char *data[5] = { "foo", "bar", "", "samba", "x"};
+ const char *data[] = { "foo", "bar", "", "samba", "x"};
char *strv = NULL;
char *t;
int i, ret;
- const int num = sizeof(data) / sizeof(data[0]);
+ const int num = ARRAY_SIZE(data);
/* Add items */
for (i = 0; i < num; i++) {
@@ -157,6 +157,37 @@ static bool test_strv_multi(struct torture_context *tctx)
return true;
}
+/* Similar to above but only add/check first 2 chars of each string */
+static bool test_strv_addn(struct torture_context *tctx)
+{
+ const char *data[] = { "foo", "bar", "samba" };
+ char *strv = NULL;
+ char *t;
+ int i, ret;
+ const int num = ARRAY_SIZE(data);
+
+ /* Add first 2 chars of each item */
+ for (i = 0; i < num; i++) {
+ ret = strv_addn(tctx, &strv, data[i], 2);
+ torture_assert(tctx, ret == 0, "strv_add() failed");
+ }
+
+ torture_assert_int_equal(tctx,
+ strv_count(strv), num,
+ "strv_count() failed");
+
+ /* Check that strv_next() finds the expected values */
+ t = NULL;
+ for (i = 0; i < num; i++) {
+ t = strv_next(strv, t);
+ torture_assert(tctx,
+ strncmp(t, data[i], 2) == 0,
+ "strv_next() failed");
+ }
+
+ return true;
+}
+
struct torture_suite *torture_local_util_strv(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite = torture_suite_create(mem_ctx, "strv");
@@ -164,6 +195,7 @@ struct torture_suite *torture_local_util_strv(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite, "strv_empty", test_strv_empty);
torture_suite_add_simple_test(suite, "strv_single", test_strv_single);
torture_suite_add_simple_test(suite, "strv_multi", test_strv_multi);
+ torture_suite_add_simple_test(suite, "strv_addn", test_strv_addn);
return suite;
}
--
Samba Shared Repository
More information about the samba-cvs
mailing list