From: Michael Tremer Date: Thu, 3 Jun 2021 17:58:07 +0000 (+0000) Subject: execute: Remove trailing newline when storing lines in array X-Git-Tag: 0.9.28~1285^2~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6635ce0867f41558a8ae3bcced9de88d6dfa1a8;p=pakfire.git execute: Remove trailing newline when storing lines in array Signed-off-by: Michael Tremer --- 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;