From 5c8f1fe0f25973a248b3fe7418d154fa400d07cc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 23 May 2013 17:38:09 +0200 Subject: mmcli: fix newline prefixing The last line in a multi-line string was getting lost if it wasn't '\n' terminated. --- cli/mmcli-common.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cli/mmcli-common.c') diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index b7d6fe66..016d8bcf 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -1145,10 +1145,15 @@ mmcli_prefix_newlines (const gchar *prefix, const gchar *line_start = str; const gchar *line_end; - while ((line_end = strchr (line_start, '\n'))) { + do { gssize line_length; - line_length = line_end - line_start; + line_end = strchr (line_start, '\n'); + if (line_end) + line_length = line_end - line_start; + else + line_length = strlen (line_start); + if (line_start[line_length - 1] == '\r') line_length--; @@ -1166,8 +1171,8 @@ mmcli_prefix_newlines (const gchar *prefix, line_length); } - line_start = line_end + 1; - } + line_start = (line_end ? line_end + 1 : NULL); + } while (line_start != NULL); return (prefixed_string ? g_string_free (prefixed_string, FALSE) : -- cgit v1.2.3-70-g09d2