diff options
| author | tgoodwin <tgoodwin> | 1998-07-10 12:32:55 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:07 +0100 |
| commit | dc6c6af3b304a8ee8d6f58ab2b5b8311e0512c37 (patch) | |
| tree | 2769f2abf7f0c1d9a4253cd2a0eae0a843977282 | |
| parent | 5290f5477832c5edc8cabf5b9709570acb7f772a (diff) | |
apply fix for use of realloc()ed memory from Scott Schwartz
| -rw-r--r-- | print.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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) { |