From d6635ce0867f41558a8ae3bcced9de88d6dfa1a8 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 3 Jun 2021 17:58:07 +0000 Subject: [PATCH] execute: Remove trailing newline when storing lines in array Signed-off-by: Michael Tremer --- src/libpakfire/execute.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libpakfire/execute.c b/src/libpakfire/execute.c index 240e5dc5a..cd69fa118 100644 --- a/src/libpakfire/execute.c +++ b/src/libpakfire/execute.c @@ -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; -- 2.47.2