diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-12-12 14:09:15 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 05:49:47 +0100 |
commit | 80b62dae14ce067fa9f13145d4ad8a8fef8b17a3 (patch) | |
tree | b1394ed93277777e602ada7bffe822bcf6e3e231 /source4/lib | |
parent | 5db23bce227b909b9577501f733e733023a2daa8 (diff) | |
download | samba-80b62dae14ce067fa9f13145d4ad8a8fef8b17a3.tar.gz samba-80b62dae14ce067fa9f13145d4ad8a8fef8b17a3.tar.bz2 samba-80b62dae14ce067fa9f13145d4ad8a8fef8b17a3.zip |
r26417: Make str_list_copy(mem_ctx, NULL) return NULL rather than an empty list.
(This used to be commit cf8636c8b77c745812376d0ea6f0fb6246a2e4fb)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/util/tests/strlist.c | 25 | ||||
-rw-r--r-- | source4/lib/util/util_strlist.c | 10 |
2 files changed, 33 insertions, 2 deletions
diff --git a/source4/lib/util/tests/strlist.c b/source4/lib/util/tests/strlist.c index 437d9d741a..3ecb982e24 100644 --- a/source4/lib/util/tests/strlist.c +++ b/source4/lib/util/tests/strlist.c @@ -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; } diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 1f1cc17d00..30de4b962d 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -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]); |