mirror of
https://github.com/samba-team/samba.git
synced 2025-11-01 16:23:49 +03:00
r26417: Make str_list_copy(mem_ctx, NULL) return NULL rather than an empty list.
This commit is contained in:
committed by
Stefan Metzmacher
parent
e9ef98b064
commit
cf8636c8b7
@@ -64,6 +64,29 @@ static bool test_lists_shell(struct torture_context *tctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool test_list_copy(struct torture_context *tctx)
|
||||
{
|
||||
const char **result;
|
||||
const char *list[] = { "foo", "bar", NULL };
|
||||
const char *empty_list[] = { NULL };
|
||||
const char **null_list = NULL;
|
||||
|
||||
result = str_list_copy(tctx, list);
|
||||
torture_assert_int_equal(tctx, str_list_length(result), 2, "list length");
|
||||
torture_assert_str_equal(tctx, result[0], "foo", "element 0");
|
||||
torture_assert_str_equal(tctx, result[1], "bar", "element 1");
|
||||
torture_assert_str_equal(tctx, result[2], NULL, "element 2");
|
||||
|
||||
result = str_list_copy(tctx, empty_list);
|
||||
torture_assert_int_equal(tctx, str_list_length(result), 0, "list length");
|
||||
torture_assert_str_equal(tctx, result[0], NULL, "element 0");
|
||||
|
||||
result = str_list_copy(tctx, null_list);
|
||||
torture_assert(tctx, result == NULL, "result NULL");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
|
||||
@@ -75,5 +98,7 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
|
||||
&test_lists_shell_strings[i]);
|
||||
}
|
||||
|
||||
torture_suite_add_simple_test(suite, "list_copy", test_list_copy);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -199,8 +199,14 @@ _PUBLIC_ size_t str_list_length(const char **list)
|
||||
_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
|
||||
{
|
||||
int i;
|
||||
const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1);
|
||||
if (ret == NULL) return NULL;
|
||||
const char **ret;
|
||||
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i=0;list && list[i];i++) {
|
||||
ret[i] = talloc_strdup(ret, list[i]);
|
||||
|
||||
Reference in New Issue
Block a user