From andrew@ugh.net.au  Sun Nov 11 20:05:07 2001
Return-Path: <andrew@ugh.net.au>
Received: from starbug.ugh.net.au (starbug.ugh.net.au [203.31.238.37])
	by hub.freebsd.org (Postfix) with ESMTP id 6D1A937B405
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 11 Nov 2001 20:05:06 -0800 (PST)
Received: by starbug.ugh.net.au (Postfix, from userid 1000)
	id CC954A842; Mon, 12 Nov 2001 15:05:03 +1100 (EST)
Message-Id: <20011112040503.CC954A842@starbug.ugh.net.au>
Date: Mon, 12 Nov 2001 15:05:03 +1100 (EST)
From: Andrew <andrew@ugh.net.au>
Reply-To: Andrew <andrew@ugh.net.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Be a bit more descriptive about realloc's usage
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         31925
>Category:       docs
>Synopsis:       Be a bit more descriptive about realloc's usage
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 11 20:10:00 PST 2001
>Closed-Date:    Fri Nov 23 19:12:28 PST 2001
>Last-Modified:  Fri Nov 23 19:13:32 PST 2001
>Originator:     Andrew
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
UgH!
>Environment:
System: FreeBSD starbug.ugh.net.au 4.4-STABLE FreeBSD 4.4-STABLE #3: Sun Oct 7 21:30:09 EST 2001 andrew@starbug.ugh.net.au:/usr/obj/usr/src/sys/STARBUG i386


	
>Description:

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

>How-To-Repeat:
	
>Fix:


--- malloc.3.orig	Sun Nov 11 08:46:56 2001
+++ malloc.3	Sun Nov 11 08:53:25 2001
@@ -115,6 +115,9 @@
 the memory referenced by
 .Fa ptr
 is valid and unchanged.
+If memory can be allocated a pointer to this memory is returned. Note this
+pointer may be different to the value passed as
+.Fa ptr .
 If
 .Fa ptr
 is
>Release-Note:
>Audit-Trail:

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

From: Andrew <andrew@ugh.net.au>
To: Giorgos Keramidas <charon@labs.gr>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: docs/31925: Be a bit more descriptive about realloc's usage
Date: Sat, 24 Nov 2001 12:47:49 +1000 (EST)

 On Thu, 22 Nov 2001, Giorgos Keramidas wrote:
 
 > 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 :)
 
 Yes I have to admit it bit me...even though I did know that from last time
 I used realloc :-)
 
 > 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?
 
 Yep I think thats great.
 
 Thanks,
 
 Andrew
 
State-Changed-From-To: open->closed 
State-Changed-By: keramida 
State-Changed-When: Fri Nov 23 19:12:28 PST 2001 
State-Changed-Why:  
Committed to -CURRENT.  Thank you Andrew :) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=31925 
>Unformatted:
