summaryrefslogtreecommitdiff
path: root/proc/info.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-07-29 07:09:14 +0000
committerMiles Bader <miles@gnu.org>1996-07-29 07:09:14 +0000
commit3da977459267a2e33b46ac351e4b271dacf42b21 (patch)
tree8dc1bc069675844330aaf6cbba2f00dd8f562e5b /proc/info.c
parentc77e7b1d62a7a8631fcabb461d30bb6e640a7719 (diff)
(get_string_array):
Correctly adjust NEWSIZE when reallocating to add very long strings.
Diffstat (limited to 'proc/info.c')
-rw-r--r--proc/info.c13
1 files 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);