[RFA] patch for argz_insert()

Charles Wilson cygwin@cwilson.fastmail.fm
Fri Mar 16 21:16:00 GMT 2007


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.

A little algebra should demonstrate the correctness of this patch.

given:
     delta = before - *argz

then:
     before = *argz + delta

therefore:
     memmove(before + len,              -> *argz + delta + len,
             before,                    -> *argz + delta,
             *argz + *argz_len - before ->
                  *argz + *argz_len - *argz - delta ->
                  *argz_len - delta
             );
     memcpy(before,   -> *argz + delta
            entry,
            len
           );

For a more thorough description, see:
http://cygwin.com/ml/cygwin/2007-03/msg00533.html

--
Chuck



-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: argz_insert.patch
URL: <http://sourceware.org/pipermail/newlib/attachments/20070316/5ef08078/attachment.ksh>


More information about the Newlib mailing list