summaryrefslogtreecommitdiff
path: root/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'print.c')
-rw-r--r--print.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/print.c b/print.c
index e0dba12..b969888 100644
--- a/print.c
+++ b/print.c
@@ -331,19 +331,20 @@ extern int fprint(int fd, const char *fmt,...) {
static void memprint_grow(Format *format, size_t more) {
char *buf;
size_t len = format->bufend - format->bufbegin + 1;
+ size_t used = format->buf - format->bufbegin;
+
len = (len >= more)
? len * 2
: ((len + more) + PRINT_ALLOCSIZE) &~ (PRINT_ALLOCSIZE - 1);
if (format->u.n)
buf = erealloc(format->bufbegin, len);
else {
- size_t used = format->buf - format->bufbegin;
buf = nalloc(len);
memcpy(buf, format->bufbegin, used);
}
- format->buf = buf + (format->buf - format->bufbegin);
+ format->buf = buf + used;
format->bufbegin = buf;
- format->bufend = buf + len - 1;
+ format->bufend = buf + len - 1;
}
static char *memprint(Format *format, const char *fmt, char *buf, size_t len) {