summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2014-10-20 19:35:23 +0000
committerschwarze <>2014-10-20 19:35:23 +0000
commitc95a384eee0578c645789ea3fd210c812b655803 (patch)
tree851c2f8d6a47706a7d55fbb2aabeb7c612e66d28 /src
parentdd4273fba31ef60efe2d1cd25f9ae3f3aa30d3ed (diff)
downloadopenbsd-c95a384eee0578c645789ea3fd210c812b655803.tar.gz
openbsd-c95a384eee0578c645789ea3fd210c812b655803.tar.bz2
openbsd-c95a384eee0578c645789ea3fd210c812b655803.zip
List extensions in the STANDARDS section, replacing some text below CAVEATS.
Remove excessive technicalities on zero-sized objects as suggested by deraadt@. contributions and ok deraadt@, ok jmc@ on an earlier version
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/malloc.363
1 files changed, 30 insertions, 33 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index d6c8b375ae..8305b14d35 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,9 +30,9 @@
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE. 31.\" SUCH DAMAGE.
32.\" 32.\"
33.\" $OpenBSD: malloc.3,v 1.80 2014/10/19 21:05:53 schwarze Exp $ 33.\" $OpenBSD: malloc.3,v 1.81 2014/10/20 19:35:23 schwarze Exp $
34.\" 34.\"
35.Dd $Mdocdate: October 19 2014 $ 35.Dd $Mdocdate: October 20 2014 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -159,12 +159,16 @@ pointer is returned and
159.Va errno 159.Va errno
160is set to 160is set to
161.Er ENOMEM . 161.Er ENOMEM .
162.Pp
162If 163If
163.Fa size 164.Fa size
164or 165or
165.Fa nmemb 166.Fa nmemb
166is equal to 0, 167is equal to 0, a unique pointer to an access protected,
167a pointer to an access protected, zero sized object is returned. 168zero sized object is returned.
169Access via this pointer will generate a
170.Dv SIGSEGV
171exception.
168.Pp 172.Pp
169If multiplying 173If multiplying
170.Fa nmemb 174.Fa nmemb
@@ -564,6 +568,28 @@ and
564.Fn free 568.Fn free
565functions conform to 569functions conform to
566.St -ansiC . 570.St -ansiC .
571.Pp
572If
573.Fa size
574or
575.Fa nmemb
576are 0, the return value is implementation defined;
577other conforming implementations may return
578.Dv NULL
579in this case.
580.Pp
581The standard does not require
582.Fn calloc
583to check for integer overflow,
584but most modern implementations provide this check.
585.Pp
586The
587.Ev MALLOC_OPTIONS
588environment variable, the file
589.Pa /etc/malloc.conf ,
590and the
591.Sx DIAGNOSTICS
592output are extensions to the standard.
567.Sh HISTORY 593.Sh HISTORY
568A 594A
569.Fn free 595.Fn free
@@ -618,35 +644,6 @@ The
618.Fn cfree 644.Fn cfree
619function appeared in SunOS 4.x. 645function appeared in SunOS 4.x.
620.Sh CAVEATS 646.Sh CAVEATS
621The
622.Fn calloc
623function checks for integer overflow in
624.Ox
625and most other modern platforms.
626Software targeting ancient platforms should not rely on this behavior.
627.Pp
628The
629.Fn malloc ,
630.Fn calloc ,
631and
632.Fn realloc
633functions have implementation defined behavior when
634.Fa size
635or
636.Fa nmemb
637are zero.
638.Pp
639Allocation of a zero size object returns a pointer to an access protected zero
640size object.
641Many zero-sized objects can be placed consecutively in shared
642protected pages.
643The minimum size of the protection on each object is suitably aligned and
644sized as previously stated, but the protection may extend further depending
645on where in a protected zone the object lands.
646Attempting to access these objects will generate a
647.Pq Dv SIGSEGV
648exception.
649.Pp
650When using 647When using
651.Fn malloc , 648.Fn malloc ,
652be wary of signed integer and 649be wary of signed integer and