From e1863c05d82096aa2bfcddb436da1b54a41369e3 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sun, 2 Feb 2014 10:51:05 -0500 Subject: * output.c: Ensure space for final nul byte in fmtbuf. Copyright-paperwork-exempt: yes --- output.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/output.c b/output.c index 000e241..b2584f1 100644 --- a/output.c +++ b/output.c @@ -591,14 +591,14 @@ static struct fmtstring static char * get_buffer (size_t need) { - /* Make sure we have room. */ + /* Make sure we have room. NEED includes space for \0. */ if (need > fmtbuf.size) { fmtbuf.size += need * 2; fmtbuf.buffer = xrealloc (fmtbuf.buffer, fmtbuf.size); } - fmtbuf.buffer[need] = '\0'; + fmtbuf.buffer[need-1] = '\0'; return fmtbuf.buffer; } @@ -629,7 +629,7 @@ message (int prefix, size_t len, const char *fmt, ...) strcat (p, "\n"); - assert (fmtbuf.buffer[len] == '\0'); + assert (fmtbuf.buffer[len-1] == '\0'); outputs (0, fmtbuf.buffer); } @@ -660,7 +660,7 @@ error (const gmk_floc *flocp, size_t len, const char *fmt, ...) strcat (p, "\n"); - assert (fmtbuf.buffer[len] == '\0'); + assert (fmtbuf.buffer[len-1] == '\0'); outputs (1, fmtbuf.buffer); } @@ -692,7 +692,7 @@ fatal (const gmk_floc *flocp, size_t len, const char *fmt, ...) strcat (p, stop); - assert (fmtbuf.buffer[len] == '\0'); + assert (fmtbuf.buffer[len-1] == '\0'); outputs (1, fmtbuf.buffer); die (2); -- cgit v1.2.3