summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoern Engel <joern@logfs.org>2012-01-16 13:39:41 -0800
committerJoern Engel <joern@logfs.org>2012-01-16 13:39:41 -0800
commitb3e1f0769bca367119d7e80be1a063f1a345fdf0 (patch)
tree900c038951f7283ef886f8cf22982724930e1a25
parent4d7cf7e91bd397bbb41f7f685d346c22188ac897 (diff)
downloadcancd-b3e1f0769bca367119d7e80be1a063f1a345fdf0.tar.gz
Prevent stray newlines
Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r--cancd.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/cancd.c b/cancd.c
index 263ba06..4d79a3d 100644
--- a/cancd.c
+++ b/cancd.c
@@ -306,8 +306,13 @@ static int write_formatted(int fd, char *buf, int count)
time_t now = time(NULL);
struct tm *tm = localtime(&now);
- count += 1; /* add terminating NUL */
- while (count) {
+ /*
+ * buf must be NUL-terminated. We add 1 to count for the terminating
+ * byte. But we also abort the loop of only the terminating byte
+ * remains, so we don't print stray newlines
+ */
+ count += 1;
+ while (count > 1) {
end = strchrnul(buf, 0xa);
*end = 0xa;
len = end - buf + 1;