log: ensure we don't truncate the final '\0' in the log
authorJens Axboe <axboe@fb.com>
Wed, 24 May 2017 03:51:59 +0000 (21:51 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 24 May 2017 03:51:59 +0000 (21:51 -0600)
Fixes: 7d64aa48 ("log: make the logging functions handle > 1024 bytes correctly")
Signed-off-by: Jens Axboe <axboe@fb.com>
log.c

diff --git a/log.c b/log.c
index f34892dc46971b233d43db7307a4dc135e521388..c7856eb74f6266e364951c4320e25ee95688e2c4 100644 (file)
--- a/log.c
+++ b/log.c
@@ -38,10 +38,10 @@ size_t log_valist(const char *str, va_list args)
                buffer = calloc(1, cur);
 
                len = vsnprintf(buffer, cur, str, args);
                buffer = calloc(1, cur);
 
                len = vsnprintf(buffer, cur, str, args);
-               if (len <= cur)
+               if (len < cur)
                        break;
 
                        break;
 
-               cur = len;
+               cur = len + 1;
                free(buffer);
        } while (1);
 
                free(buffer);
        } while (1);
 
@@ -64,10 +64,10 @@ size_t log_info(const char *format, ...)
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
-               if (len <= cur)
+               if (len < cur)
                        break;
 
                        break;
 
-               cur = len;
+               cur = len + 1;
                free(buffer);
        } while (1);
 
                free(buffer);
        } while (1);
 
@@ -90,10 +90,10 @@ size_t __log_buf(struct buf_output *buf, const char *format, ...)
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
-               if (len <= cur)
+               if (len < cur)
                        break;
 
                        break;
 
-               cur = len;
+               cur = len + 1;
                free(buffer);
        } while (1);
 
                free(buffer);
        } while (1);
 
@@ -124,10 +124,10 @@ size_t log_err(const char *format, ...)
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
                len = vsnprintf(buffer, cur, format, args);
                va_end(args);
 
-               if (len <= cur)
+               if (len < cur)
                        break;
 
                        break;
 
-               cur = len;
+               cur = len + 1;
                free(buffer);
        } while (1);
 
                free(buffer);
        } while (1);