Date: Wed, 21 Nov 2001 19:10:02 -0800 (PST) From: Giorgos Keramidas <charon@labs.gr> To: freebsd-doc@freebsd.org Subject: Re: docs/31925: Be a bit more descriptive about realloc's usage Message-ID: <200111220310.fAM3A2154823@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR docs/31925; it has been noted by GNATS. From: Giorgos Keramidas <charon@labs.gr> To: Andrew <andrew@ugh.net.au> Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: docs/31925: Be a bit more descriptive about realloc's usage Date: Thu, 22 Nov 2001 04:59:54 +0200 On 2001-11-12 15:05:03, Andrew wrote: > The existing malloc(3) page doesn't make it clear that realloc may return a > pointer to a completely different memory block than the one passed to it. I > hope this patch makes things a bit clearer for people programming while tired ;) Andrew, thanks for pointing this out. A very usual cause of bugs when realloc() is used is to assume that realloc() returns the same value passed as a parameter :) A few lines above the changed lines, malloc.3 uses `newly allocated portion of memory' to refer to the result of realloc(3). What do you think of the following diff, which is derived from your changes? Index: malloc.3 =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/malloc.3,v retrieving revision 1.49 diff -8 -u -r1.49 malloc.3 --- malloc.3 5 Nov 2001 00:39:27 -0000 1.49 +++ malloc.3 22 Nov 2001 02:53:08 -0000 @@ -112,16 +112,20 @@ If the new size is larger, the value of the newly allocated portion of the memory is undefined. If the requested memory cannot be allocated, .Dv NULL is returned and the memory referenced by .Fa ptr is valid and unchanged. +If memory can be allocated a pointer to the newly allocated portion of +the memory is returned. Note that this may be different from the value +passed as +.Fa ptr . If .Fa ptr is .Dv NULL , the .Fn realloc function behaves identically to .Fn malloc To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-doc" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111220310.fAM3A2154823>