]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
parser: Refactor joining strings
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 12:27:49 +0000 (12:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 12:27:49 +0000 (12:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c

index 74a3f6c6bccf04e92f165c2d77aef496603e48a1..6ece68982fbc65ca2e390f8d7b92b1f0a19f12b5 100644 (file)
@@ -265,11 +265,18 @@ static char* pakfire_parser_join(const char* c, const char* val1, const char* va
        char* result = NULL;
        int r;
 
+       if (!val1)
+               val1 = "";
+
+       if (!val2)
+               val2 = "";
+
+       // Reset the delimiter if we don't need it
+       if (!*val1 || !*val2)
+               c = "";
+
        // Join both strings
-       r = asprintf(&result, "%s%s%s",
-                       (val1) ? val1 : "",
-                       (val1 && *val1 && val2 && *val2) ? c : "",
-                       (val2) ? val2 : "");
+       r = asprintf(&result, "%s%s%s", val1, c, val2);
        if (r < 0)
                return NULL;