summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-05-23 17:38:09 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-05-23 18:00:03 +0200
commit5c8f1fe0f25973a248b3fe7418d154fa400d07cc (patch)
treea8a8943eb1c29e1a4ef57da0ac3616ad1d19ca22
parenta12be165d14083c11d9f8f916b1dd82ae3cf9e21 (diff)
downloadModemManager-5c8f1fe0f25973a248b3fe7418d154fa400d07cc.tar.gz
mmcli: fix newline prefixing
The last line in a multi-line string was getting lost if it wasn't '\n' terminated.
-rw-r--r--cli/mmcli-common.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c
index b7d6fe664..016d8bcfb 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) :