]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r327674, r327796
authorkp <kp@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 23 Jan 2018 04:37:31 +0000 (04:37 +0000)
committerkp <kp@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 23 Jan 2018 04:37:31 +0000 (04:37 +0000)
commit464d00d7bbef1bd811d20a5982cd96e2c406adcd
tree053ce96f42f9d34f011c0a2889e6d98010509189
parentadd8c50506bc01a582c20d2262bd3b31c87f4294
MFC r327674, r327796

Introduce mallocarray() in the kernel

Similar to calloc() the mallocarray() function checks for integer
overflows before allocating memory.
It does not zero memory, unless the M_ZERO flag is set.

Additionally, move the overflow check logic out to WOULD_OVERFLOW() for
consumers to have a common means of testing for overflowing allocations.
WOULD_OVERFLOW() should be a secondary check -- on 64-bit platforms, just
because an allocation won't overflow size_t does not mean it is a sane size
to request.  Callers should be imposing reasonable allocation limits far,
far, below overflow.

Obtained from: OpenBSD

git-svn-id: svn://svn.freebsd.org/base/stable/10@328276 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
share/man/man9/malloc.9
sys/kern/kern_malloc.c
sys/sys/malloc.h