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.
This commit is contained in:
Jeff Johnston 2007-03-16 21:16:09 +00:00
parent a167bcd8e5
commit 443871a60b
2 changed files with 12 additions and 2 deletions

View File

@ -1,3 +1,10 @@
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.
2007-03-16 Eric Blake <ebb9@byu.net>
* libc/stdio64/fseek064.c (_fseeko64_r): Fix reentrancy.

View File

@ -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;