Browse Source

make RETURN VALUES more concise

and fix two instances of "new sentence, new line" while here
feedback and ok jmc@, ok doug@
OPENBSD_5_7
schwarze 10 years ago
parent
commit
c1547cfc1f
1 changed files with 28 additions and 77 deletions
  1. +28
    -77
      src/lib/libc/stdlib/malloc.3

+ 28
- 77
src/lib/libc/stdlib/malloc.3 View File

@ -30,7 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: malloc.3,v 1.79 2014/10/19 17:58:14 doug Exp $
.\" $OpenBSD: malloc.3,v 1.80 2014/10/19 21:05:53 schwarze Exp $
.\"
.Dd $Mdocdate: October 19 2014 $
.Dt MALLOC 3
@ -97,6 +97,14 @@ If the space cannot be allocated, the object
pointed to by
.Fa ptr
is unchanged.
If
.Fa ptr
is
.Dv NULL ,
.Fn realloc
behaves like
.Fn malloc
and allocates a new object.
.Pp
The
.Fn reallocarray
@ -139,95 +147,38 @@ function is also provided for compatibility with old systems and other
libraries; it is simply an alias for
.Fn free .
.Sh RETURN VALUES
If
Upon successful completion, the functions
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
or
.Fn reallocarray
is called with
.Fa size
or
.Fa nmemb
is equal to 0,
a pointer to an access protected, zero sized object is returned.
.Pp
If
.Fn malloc
is called with
.Fa size
greater than 0, it returns a pointer to the allocated space if successful;
otherwise, a
.Dv NULL
pointer is returned and
.Va errno
is set to
.Er ENOMEM .
.Pp
The
.Fn calloc
function checks for integer overflow and returns
.Dv NULL
if
.Fa nmemb
*
.Fa size
will result in integer overflow.
If
.Fa nmemb
and
.Fa size
are greater than 0,
.Fn calloc
returns a pointer to the allocated space if successful; otherwise, a
.Fn reallocarray
return a pointer to the allocated space; otherwise, a
.Dv NULL
pointer is returned and
.Va errno
is set to
.Er ENOMEM .
.Pp
The
.Fn realloc
function behaves like
.Fn malloc
for the specified
.Fa size
when
.Fa ptr
is
.Dv NULL .
If
.Fa size
is greater than 0,
.Fn realloc
returns a pointer to the allocated space if successful; otherwise, a
.Dv NULL
pointer is returned and
.Va errno
is set to
.Er ENOMEM .
or
.Fa nmemb
is equal to 0,
a pointer to an access protected, zero sized object is returned.
.Pp
The
.Fn reallocarray
function checks for integer overflow and returns
.Dv NULL
if
If multiplying
.Fa nmemb
*
.Fa size
will result in integer overflow.
If
.Fn reallocarray
is called with
and
.Fa size
results in integer overflow,
.Fn calloc
and
.Fa nmemb
greater than 0, it returns a pointer to the allocated space if successful;
otherwise, a
.Fn reallocarray
return
.Dv NULL
pointer is returned and
and set
.Va errno
is set to
to
.Er ENOMEM .
.Pp
The
@ -315,8 +266,8 @@ Code designed for some ancient platforms avoided calling
with a
.Dv NULL
.Fa ptr .
Such hacks are no longer necessary in modern code. Instead of
this idiom:
Such hacks are no longer necessary in modern code.
Instead of this idiom:
.Bd -literal -offset indent
if (p == NULL)
newp = malloc(newsize);
@ -361,8 +312,8 @@ if ((p = malloc(size * num)) == NULL)
err(1, "malloc");
.Ed
.Pp
The above test is not sufficient in all cases. For example, multiplying
ints requires a different set of checks:
The above test is not sufficient in all cases.
For example, multiplying ints requires a different set of checks:
.Bd -literal -offset indent
int size;
int num;


Loading…
Cancel
Save