diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2007-03-17 00:16:09 +0300 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2007-03-17 00:16:09 +0300 |
commit | 443871a60b935dcd2ca643cf1fde189c9c6540ac (patch) | |
tree | 577ca1796834d01cf86b6c37319a0b817796bb43 /newlib/libc/argz | |
parent | a167bcd8e59baf24d5a200d0c3e31817433974c6 (diff) |
2007-03-16 Charles Wilson <cygwin@...>
* libc/argz/argz_insert.c: "before" pointer is
invalid after *argz realloc. Compute offset
between "before" and *argz, and use it after
reallocation instead.
Diffstat (limited to 'newlib/libc/argz')
-rw-r--r-- | newlib/libc/argz/argz_insert.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/newlib/libc/argz/argz_insert.c b/newlib/libc/argz/argz_insert.c index 8a9fb19b2..3ae662116 100644 --- a/newlib/libc/argz/argz_insert.c +++ b/newlib/libc/argz/argz_insert.c @@ -28,13 +28,16 @@ _DEFUN (argz_insert, (argz, argz_len, before, entry), while (before != *argz && before[-1]) before--; + /* delta will always be non-negative, and < *argz_len */ + ptrdiff_t delta = before - *argz; + len = strlen(entry) + 1; if(!(*argz = (char *)realloc(*argz, *argz_len + len))) return ENOMEM; - memmove(before + len, before, *argz + *argz_len - before); - memcpy(before, entry, len); + memmove(*argz + delta + len, *argz + delta, *argz_len - delta); + memcpy(*argz + delta, entry, len); *argz_len += len; |