diff options
author | Joern Engel <joern@logfs.org> | 2012-01-16 13:39:41 -0800 |
---|---|---|
committer | Joern Engel <joern@logfs.org> | 2012-01-16 13:39:41 -0800 |
commit | b3e1f0769bca367119d7e80be1a063f1a345fdf0 (patch) | |
tree | 900c038951f7283ef886f8cf22982724930e1a25 | |
parent | 4d7cf7e91bd397bbb41f7f685d346c22188ac897 (diff) | |
download | cancd-b3e1f0769bca367119d7e80be1a063f1a345fdf0.tar.gz |
Prevent stray newlines
Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r-- | cancd.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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; |