diff options
-rw-r--r-- | cli/mmcli-common.c | 13 |
1 files changed, 9 insertions, 4 deletions
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) : |