Browse Source

Some tweaks from jmc@ and describe better what recallocarray does;

help and ok from tom@ and deraadt@
OPENBSD_6_1
otto 7 years ago
parent
commit
dddd0ad99b
1 changed files with 16 additions and 7 deletions
  1. +16
    -7
      src/lib/libc/stdlib/malloc.3

+ 16
- 7
src/lib/libc/stdlib/malloc.3 View File

@ -30,15 +30,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $OpenBSD: malloc.3,v 1.102 2017/03/06 18:44:21 otto Exp $
.\" $OpenBSD: malloc.3,v 1.103 2017/03/07 06:07:50 otto Exp $
.\" .\"
.Dd $Mdocdate: March 6 2017 $
.Dd $Mdocdate: March 7 2017 $
.Dt MALLOC 3 .Dt MALLOC 3
.Os .Os
.Sh NAME .Sh NAME
.Nm malloc , .Nm malloc ,
.Nm calloc , .Nm calloc ,
.Nm reallocarray , .Nm reallocarray ,
.Nm recallocarray ,
.Nm realloc , .Nm realloc ,
.Nm free .Nm free
.Nd memory allocation and deallocation .Nd memory allocation and deallocation
@ -118,7 +119,9 @@ The
.Fn recallocarray .Fn recallocarray
function is similar to function is similar to
.Fn reallocarray .Fn reallocarray
except that it takes care of clearing newly allocated and freed memory.
except that it takes care of clearing newly allocated memory.
Additionally, the memory that becomes unallocated while shrinking
or moving existing allocations is erased.
If If
.Fa ptr .Fa ptr
is a is a
@ -135,9 +138,9 @@ pointer,
.Fa oldnmemb .Fa oldnmemb
must be a value such that must be a value such that
.Fa oldnmemb .Fa oldnmemb
*
*
.Fa size .Fa size
is the size of an earlier allocation that returned
is the size of the earlier allocation that returned
.Fa ptr , .Fa ptr ,
otherwise the behaviour is undefined. otherwise the behaviour is undefined.
.Pp .Pp
@ -204,7 +207,7 @@ to
.Er ENOMEM . .Er ENOMEM .
.Pp .Pp
If If
.Fa ptr
.Fa ptr
is not NULL and multiplying is not NULL and multiplying
.Fa oldnmemb .Fa oldnmemb
and and
@ -220,8 +223,10 @@ to
.Sh IDIOMS .Sh IDIOMS
Consider Consider
.Fn calloc .Fn calloc
or the extension
or the extensions
.Fn reallocarray .Fn reallocarray
and
.Fn recallocarray
when there is multiplication in the when there is multiplication in the
.Fa size .Fa size
argument of argument of
@ -547,6 +552,10 @@ The
.Fn reallocarray .Fn reallocarray
function appeared in function appeared in
.Ox 5.6 . .Ox 5.6 .
The
.Fn recallocarray
function appeared in
.Ox 6.1 .
.Sh CAVEATS .Sh CAVEATS
When using When using
.Fn malloc , .Fn malloc ,


Loading…
Cancel
Save