[PATCH 4/7] log: Print truncated messages

Ian Jackson ijackson at chiark.greenend.org.uk
Thu Jun 14 01:38:34 BST 2012


If a message doesn't survive the vsnprintf in vMessage untruncated,
the result may be that its newline is lost.  After that, buff will
never manage to gain a newline and all further messages will be
discarded.

Fix this by always putting "\n\0" at the end of buff.  That way a
truncated message is printed and the buffer will be cleared out for
the next call.

Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 log.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/log.c b/log.c
index 4f1b651..9cd0572 100644
--- a/log.c
+++ b/log.c
@@ -38,6 +38,8 @@ static void vMessage(uint32_t class, const char *message, va_list args)
 	bp=strlen(buff);
 	assert(bp < MESSAGE_BUFLEN);
 	vsnprintf(buff+bp,MESSAGE_BUFLEN-bp,message,args);
+	buff[sizeof(buff)-2] = '\n';
+	buff[sizeof(buff)-1] = '\0';
 	/* Each line is sent separately */
 	while ((nlp=strchr(buff,'\n'))) {
 	    *nlp=0;
-- 
1.7.2.5




More information about the sgo-software-discuss mailing list