| Summary: | Be a bit more descriptive about realloc's usage | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Documentation | Reporter: | Andrew Stevenson <andrew> | ||||
| Component: | Books & Articles | Assignee: | freebsd-doc (Nobody) <doc> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | Latest | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
|
Description
Andrew Stevenson
2001-11-12 04:10:00 UTC
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
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 Committed to -CURRENT. Thank you Andrew :) |