From 3da977459267a2e33b46ac351e4b271dacf42b21 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 29 Jul 1996 07:09:14 +0000 Subject: (get_string_array): Correctly adjust NEWSIZE when reallocating to add very long strings. --- proc/info.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/proc/info.c b/proc/info.c index a9b49ff7..c44bde6a 100644 --- a/proc/info.c +++ b/proc/info.c @@ -270,12 +270,14 @@ get_string_array (task_t t, } len = strlen (string) + 1; - if (len > (char *) *buf + *buflen - bp) + if (len > *(char **)buf + *buflen - bp) { vm_address_t newbuf; + vm_size_t prev_len = bp - *(char **)buf; vm_size_t newsize = *buflen * 2; - if (newsize < len) - newsize = len; + + if (newsize < prev_len + len) + newsize = prev_len + len; err = vm_allocate (mach_task_self (), &newbuf, newsize, 1); if (err) @@ -287,14 +289,15 @@ get_string_array (task_t t, return err; } - bcopy (*(char **) buf, (char *) newbuf, bp - (char *) *buf); - bp = newbuf + (bp - *buf); + bcopy (*(char **) buf, (char *) newbuf, prev_len); + bp = (char *)newbuf + prev_len; if (*buf != origbuf) vm_deallocate (mach_task_self (), *buf, *buflen); *buf = newbuf; *buflen = newsize; } + bcopy (string, bp, len); bp += len; free (string); -- cgit v1.2.3