rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit dc6c6af3b304a8ee8d6f58ab2b5b8311e0512c37
parent 5290f5477832c5edc8cabf5b9709570acb7f772a
Author: tgoodwin <tgoodwin>
Date:   Fri, 10 Jul 1998 12:32:55 +0000

apply fix for use of realloc()ed memory from Scott Schwartz

Diffstat:
Mprint.c | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git 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) {