summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/tests/strlist.c51
-rw-r--r--lib/util/util.h2
-rw-r--r--lib/util/util_strlist.c3
3 files changed, 30 insertions, 26 deletions
diff --git a/lib/util/tests/strlist.c b/lib/util/tests/strlist.c
index a974f58184..8940dab415 100644
--- a/lib/util/tests/strlist.c
+++ b/lib/util/tests/strlist.c
@@ -30,7 +30,7 @@ struct test_list_element {
const char *list[5];
};
-struct test_list_element test_lists_strings[] = {
+const struct test_list_element test_lists_strings[] = {
{
.list_as_string = "",
.list = { NULL }
@@ -63,7 +63,7 @@ struct test_list_element test_lists_strings[] = {
}
};
-struct test_list_element test_lists_shell_strings[] = {
+const struct test_list_element test_lists_shell_strings[] = {
{
.list_as_string = "",
.list = { NULL }
@@ -99,18 +99,18 @@ struct test_list_element test_lists_shell_strings[] = {
}
};
-static bool test_lists_shell(struct torture_context *tctx,
- const void *data)
+static bool test_lists_shell(struct torture_context *tctx, const void *data)
{
const struct test_list_element *element = data;
- const char **ret1, **ret2, *tmp;
+
+ char **ret1, **ret2, *tmp;
bool match = true;
TALLOC_CTX *mem_ctx = tctx;
ret1 = str_list_make_shell(mem_ctx, element->list_as_string, element->seperators);
torture_assert(tctx, ret1, "str_list_make_shell() must not return NULL");
- tmp = str_list_join_shell(mem_ctx, ret1, element->seperators ? *element->seperators : ' ');
+ tmp = str_list_join_shell(mem_ctx, (const char **) ret1, element->seperators ? *element->seperators : ' ');
ret2 = str_list_make_shell(mem_ctx, tmp, element->seperators);
if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
@@ -130,7 +130,8 @@ static bool test_lists_shell(struct torture_context *tctx,
torture_assert(tctx, match, talloc_asprintf(tctx,
"str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", element->list_as_string, tmp));
- torture_assert(tctx, str_list_equal(ret1, element->list),
+ torture_assert(tctx, str_list_equal((const char * const *) ret1,
+ element->list),
talloc_asprintf(tctx,
"str_list_make_shell(%s) failed to create correct list",
element->list_as_string));
@@ -141,10 +142,12 @@ static bool test_lists_shell(struct torture_context *tctx,
static bool test_list_make(struct torture_context *tctx, const void *data)
{
const struct test_list_element *element = data;
+
char **result;
result = str_list_make(tctx, element->list_as_string, element->seperators);
torture_assert(tctx, result, "str_list_make() must not return NULL");
- torture_assert(tctx, str_list_equal((const char **)result, element->list),
+ torture_assert(tctx, str_list_equal((const char * const *) result,
+ element->list),
talloc_asprintf(tctx,
"str_list_make(%s) failed to create correct list",
element->list_as_string));
@@ -250,7 +253,7 @@ static bool test_list_length(struct torture_context *tctx)
static bool test_list_add(struct torture_context *tctx)
{
- char **result, **result2;
+ const char **result, **result2;
const char *list[] = {
"element_0",
"element_1",
@@ -258,9 +261,9 @@ static bool test_list_add(struct torture_context *tctx)
"element_3",
NULL
};
- result = str_list_make(tctx, "element_0, element_1, element_2", NULL);
+ result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL);
torture_assert(tctx, result, "str_list_make() must not return NULL");
- result2 = str_list_add(result, "element_3");
+ result2 = str_list_add((const char **) result, "element_3");
torture_assert(tctx, result2, "str_list_add() must not return NULL");
torture_assert(tctx, str_list_equal(result2, list),
"str_list_add() failed");
@@ -270,7 +273,7 @@ static bool test_list_add(struct torture_context *tctx)
static bool test_list_add_const(struct torture_context *tctx)
{
- char **result, **result2;
+ const char **result, **result2;
const char *list[] = {
"element_0",
"element_1",
@@ -278,7 +281,7 @@ static bool test_list_add_const(struct torture_context *tctx)
"element_3",
NULL
};
- result = str_list_make(tctx, "element_0, element_1, element_2", NULL);
+ result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL);
torture_assert(tctx, result, "str_list_make() must not return NULL");
result2 = str_list_add_const(result, "element_3");
torture_assert(tctx, result2, "str_list_add_const() must not return NULL");
@@ -290,14 +293,14 @@ static bool test_list_add_const(struct torture_context *tctx)
static bool test_list_remove(struct torture_context *tctx)
{
- char **result;
+ const char **result;
const char *list[] = {
"element_0",
"element_1",
"element_3",
NULL
};
- result = str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL);
+ result = (const char **) str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL);
torture_assert(tctx, result, "str_list_make() must not return NULL");
str_list_remove(result, "element_2");
torture_assert(tctx, str_list_equal(result, list),
@@ -336,7 +339,7 @@ static bool test_list_check_ci(struct torture_context *tctx)
static bool test_list_unique(struct torture_context *tctx)
{
- char **result;
+ const char **result;
const char *list[] = {
"element_0",
"element_1",
@@ -354,7 +357,7 @@ static bool test_list_unique(struct torture_context *tctx)
"element_2",
NULL
};
- result = str_list_copy(tctx, list_dup);
+ result = (const char **) str_list_copy(tctx, list_dup);
/* We must copy the list, as str_list_unique does a talloc_realloc() on it's parameter */
result = str_list_unique(result);
torture_assert(tctx, result, "str_list_unique() must not return NULL");
@@ -398,7 +401,7 @@ static bool test_list_unique_2(struct torture_context *tctx)
static bool test_list_append(struct torture_context *tctx)
{
- char **result;
+ const char **result;
const char *list[] = {
"element_0",
"element_1",
@@ -420,7 +423,7 @@ static bool test_list_append(struct torture_context *tctx)
"element_5",
NULL
};
- result = str_list_copy(tctx, list);
+ result = (const char **) str_list_copy(tctx, list);
torture_assert(tctx, result, "str_list_copy() must not return NULL");
result = str_list_append(result, list2);
torture_assert(tctx, result, "str_list_append() must not return NULL");
@@ -432,7 +435,7 @@ static bool test_list_append(struct torture_context *tctx)
static bool test_list_append_const(struct torture_context *tctx)
{
- char **result;
+ const char **result;
const char *list[] = {
"element_0",
"element_1",
@@ -454,7 +457,7 @@ static bool test_list_append_const(struct torture_context *tctx)
"element_5",
NULL
};
- result = str_list_copy(tctx, list);
+ result = (const char **) str_list_copy(tctx, list);
torture_assert(tctx, result, "str_list_copy() must not return NULL");
result = str_list_append_const(result, list2);
torture_assert(tctx, result, "str_list_append_const() must not return NULL");
@@ -471,12 +474,12 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
for (i = 0; i < ARRAY_SIZE(test_lists_shell_strings); i++) {
torture_suite_add_simple_tcase_const(suite, "lists_shell",
- test_lists_shell, &test_lists_shell_strings[i]);
+ test_lists_shell, &test_lists_shell_strings[i]);
}
for (i = 0; i < ARRAY_SIZE(test_lists_strings); i++) {
- torture_suite_add_simple_tcase_const(suite, "lists",
- test_list_make, &test_lists_strings[i]);
+ torture_suite_add_simple_tcase_const(suite, "list_make",
+ test_list_make, &test_lists_strings[i]);
}
torture_suite_add_simple_test(suite, "list_copy", test_list_copy);
diff --git a/lib/util/util.h b/lib/util/util.h
index 159f812d98..e7ea0ba527 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -477,7 +477,7 @@ _PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
/**
Return true if all the elements of the list match exactly.
*/
-_PUBLIC_ bool str_list_equal(const char **list1, const char **list2);
+_PUBLIC_ bool str_list_equal(const char * const *list1, const char * const *list2);
/**
add an entry to a string list
diff --git a/lib/util/util_strlist.c b/lib/util/util_strlist.c
index 8d69eef233..71998b9a5c 100644
--- a/lib/util/util_strlist.c
+++ b/lib/util/util_strlist.c
@@ -264,7 +264,8 @@ _PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
/**
Return true if all the elements of the list match exactly.
*/
-_PUBLIC_ bool str_list_equal(const char **list1, const char **list2)
+_PUBLIC_ bool str_list_equal(const char * const *list1,
+ const char * const *list2)
{
int i;