]> git.ipfire.org Git - pakfire.git/commitdiff
execute: Remove trailing newline when storing lines in array
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2021 17:58:07 +0000 (17:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2021 17:58:07 +0000 (17:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/execute.c

index 240e5dc5aafc8a70ea36930bf56aadd1cb28f61d..cd69fa1183a00fea47077d261affbd9207b625ef 100644 (file)
@@ -291,6 +291,14 @@ int pakfire_execute_capture_stdout_to_array(Pakfire pakfire, void* data, int pri
        if (priority == LOG_INFO) {
                unsigned int length = 0;
 
+               // Create a copy of line
+               char* message = strdup(line);
+               if (!message)
+                       return 1;
+
+               // Remove any trailing newline
+               pakfire_remove_trailing_newline(message);
+
                // Determine the length of the existing array
                if (*array) {
                        for (char** element = *array; *element; element++)
@@ -302,8 +310,8 @@ int pakfire_execute_capture_stdout_to_array(Pakfire pakfire, void* data, int pri
                if (!*array)
                        return 1;
 
-               // Append line and terminate the array
-               (*array)[length] = strdup(line);
+               // Append message and terminate the array
+               (*array)[length] = message;
                (*array)[length + 1] = NULL;
 
                return 0;