From owner-freebsd-doc Wed Nov 21 19:10: 6 2001 Delivered-To: freebsd-doc@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4BD0637B418 for ; Wed, 21 Nov 2001 19:10:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id fAM3A2154823; Wed, 21 Nov 2001 19:10:02 -0800 (PST) (envelope-from gnats) Date: Wed, 21 Nov 2001 19:10:02 -0800 (PST) Message-Id: <200111220310.fAM3A2154823@freefall.freebsd.org> To: freebsd-doc@freebsd.org Cc: From: Giorgos Keramidas Subject: Re: docs/31925: Be a bit more descriptive about realloc's usage Reply-To: Giorgos Keramidas Sender: owner-freebsd-doc@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR docs/31925; it has been noted by GNATS. From: Giorgos Keramidas To: Andrew 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