malloc.3: Note that calloc() detects overflow when multiplying its arguments

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2018-07-04 10:03:01 +02:00
parent d4f4d3f63f
commit b7b0f18926
1 changed files with 17 additions and 0 deletions

View File

@ -107,6 +107,23 @@ returns either NULL,
.\" glibc does this:
or a unique pointer value that can later be successfully passed to
.BR free ().
If the multiplication of
.I nmemb
and
.I size
would result in integer overflow, then
.BR calloc ()
returns an error.
By contrast,
an integer overflow would not be detected in the following call to
.BR malloc (),
with the result that an incorrectly sized block of memory would be allocated:
.PP
.in +4n
.EX
malloc(nmemb * size);
.EE
.in
.PP
The
.BR realloc ()