]> git.ipfire.org Git - pakfire.git/commitdiff
string: Constify inputs when joining strings
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 13:37:53 +0000 (13:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 26 Oct 2024 13:37:53 +0000 (13:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c
src/libpakfire/include/pakfire/string.h
src/libpakfire/solution.c
src/libpakfire/string.c
tests/libpakfire/string.c

index 997cbbaea36b57e459a22149359027dda32e0f9f..72cf819afeba2b293ebbb1cc5a80e4c2fd878ec4 100644 (file)
@@ -1432,7 +1432,7 @@ int pakfire_db_add_package(struct pakfire_db* db,
        groups = pakfire_package_get_strings(pkg, PAKFIRE_PKG_GROUPS);
        if (groups) {
                // Join everything together as SQLite doesn't support arrays
-               __groups = pakfire_string_join(groups, " ");
+               __groups = pakfire_string_join((const char**)groups, " ");
                if (!__groups) {
                        r = 1;
                        goto ERROR;
index b88b1fbb8a152c8396895545a163c75cda3e6a57..e3974e90aae7d2e2a9584b4c13e41b4bb74e0bc5 100644 (file)
@@ -60,7 +60,7 @@ void pakfire_string_unquote(char* s);
 
 int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2);
 char* pakfire_string_replace(const char* s, const char* pattern, const char* repl);
-char* pakfire_string_join(char** list, const char* delim);
+char* pakfire_string_join(const char** list, const char* delim);
 
 /*
        Simple operations, usually used in the linter...
index cc69e3a7bcaba8f233eee03c33e77a301700e7e9..1ed93e6e674b0ad6725cf985eca2910b795ad393 100644 (file)
@@ -196,7 +196,7 @@ static char* pakfire_solution_make_string(struct pakfire_solution* solution) {
        elements[count] = NULL;
 
        // All okay, concat result string
-       s = pakfire_string_join(elements, "\n");
+       s = pakfire_string_join((const char**)elements, "\n");
 
 ERROR:
        if (transaction)
index eba9711648eeefe4091918b5f6473c37c6e90f1d..10348ca4463cb9db716911c87a8057c97fea407d 100644 (file)
@@ -257,7 +257,7 @@ ERROR:
        return NULL;
 }
 
-char* pakfire_string_join(char** list, const char* delim) {
+char* pakfire_string_join(const char** list, const char* delim) {
        // Validate input
        if (!list || !delim) {
                errno = EINVAL;
@@ -268,7 +268,7 @@ char* pakfire_string_join(char** list, const char* delim) {
        unsigned int elements = 0;
 
        // Count the number of elements and the total length
-       for (char** item = list; *item; item++) {
+       for (const char** item = list; *item; item++) {
                length += strlen(*item);
                elements++;
        }
@@ -291,7 +291,7 @@ char* pakfire_string_join(char** list, const char* delim) {
        size_t bytes_left = length + 1;
        size_t bytes_written;
 
-       for (char** item = list; *item; item++) {
+       for (const char** item = list; *item; item++) {
                bytes_written = snprintf(p, bytes_left, "%s", *item);
 
                bytes_left -= bytes_written;
index 4bab173277fef6de2f5a6ac2225fa5a99152602e..0412b47f0176f29b98cff7d16517bc526e29f45a 100644 (file)
@@ -169,7 +169,7 @@ static int test_string_join(const struct test* t) {
        char* s = NULL;
 
        // Some test elements
-       char* elements1[] = {
+       const char* elements1[] = {
                "A",
                "B",
                "C",
@@ -194,7 +194,7 @@ static int test_string_join(const struct test* t) {
                s = NULL;
        }
 
-       char* elements2[] = {
+       const char* elements2[] = {
                "",
                "",
                "",
@@ -220,7 +220,7 @@ static int test_string_join(const struct test* t) {
        s = pakfire_string_join(NULL, "\n");
        ASSERT_ERRNO(!s, EINVAL);
 
-       char* elements3[] = {
+       const char* elements3[] = {
                NULL,
        };