]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Initialize strings correctly
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 5 Oct 2023 09:58:25 +0000 (09:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 5 Oct 2023 09:58:25 +0000 (09:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c
src/libpakfire/transaction.c

index dbe5298a87411d9871a406e185938ddd6dc5b8f9..c94f3f9ffaa401c670a322f0537e0f8ab4c4350d 100644 (file)
@@ -1477,7 +1477,7 @@ PAKFIRE_EXPORT struct pakfire_repo* pakfire_package_get_repo(struct pakfire_pack
 
 static void pakfire_package_dump_add_line(char** str, const char* key, const char* val) {
        if (val)
-               asprintf(str, "%s%-15s: %s\n", *str, key ? key : "", val);
+               asprintf(str, "%s%-15s: %s\n", (*str) ? *str : "", key ? key : "", val);
 }
 
 static void pakfire_package_dump_add_lines(char** str, const char* key, char** lines) {
@@ -1551,7 +1551,7 @@ static int pakfire_sort_dependencies(const void* p1, const void* p2) {
 }
 
 PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags) {
-       char* string = "";
+       char* string = NULL;
 
        // Name
        const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME);
index 19a88469f478d359deac454de2bd4a70e3ed164a..c80e3138b6cdc45d1d97134f0aca5a40e820e667 100644 (file)
@@ -520,7 +520,7 @@ static int pakfire_transaction_append_problems(
 static char* pakfire_transaction_get_problem_string(
                struct pakfire_transaction* transaction, int flags) {
        struct pakfire_problem** problems = NULL;
-       char* buffer = "";
+       char* buffer = NULL;
        int r;
 
        // Fetch any problems
@@ -946,7 +946,7 @@ static int pakfire_transaction_add_separator(char** s, size_t width) {
 
        // Write line of =
        for (unsigned int i = 0; i < width; i++) {
-               r = asprintf(s, "%s=", *s);
+               r = asprintf(s, "%s=", (*s) ? *s : "");
                if (r < 0)
                        return r;
        }
@@ -972,7 +972,7 @@ static int pakfire_transaction_add_usage_line(char** s, size_t width,
 
 PAKFIRE_EXPORT char* pakfire_transaction_dump(struct pakfire_transaction* transaction, size_t width) {
        char headline[1024];
-       char* s = "";
+       char* s = NULL;
        int r;
 
        Queue classes;