]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/sysdep.c
sysdep.c: cprintf() truncation fix (Phil Slack)
[citadel.git] / citadel / server / sysdep.c
index 702cc2a90299c2fb11cda206697738626e69ccfd..21ba4c7b055d1eefce318cf308d1b8d95be6be2b 100644 (file)
@@ -369,11 +369,21 @@ void cputbuf(const StrBuf *Buf) {
 void cprintf(const char *format, ...) {   
        va_list arg_ptr;   
        char buf[1024];
+       int rc;
    
        va_start(arg_ptr, format);   
-       if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
-               buf[sizeof buf - 2] = '\n';
-       client_write(buf, strlen(buf)); 
+       rc = vsnprintf(buf, sizeof buf, format, arg_ptr);
+       if (rc < 0) {
+               syslog(LOG_ERR,"Console output error occured. Format: %s",format);
+       } else {
+               if (rc >= sizeof buf) {
+                       // Output was truncated.
+                       // Chop at the end of the buffer
+                       buf[sizeof buf - 2] = '\n';
+                       buf[sizeof buf - 1] = 0;
+               }
+               client_write(buf, strlen(buf)); 
+       }
        va_end(arg_ptr);
 }