summaryrefslogtreecommitdiff
path: root/doc/posix-functions/malloc.texi
blob: 028f1dca5c53bbbd66050624656617db8f573e97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@node malloc
@section @code{malloc}
@findex malloc

POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html}

Gnulib module: malloc-posix

Portability problems fixed by Gnulib:
@itemize
@item
Upon failure, the function does not set @code{errno} to @code{ENOMEM} on
some platforms:
mingw, MSVC 14.

@item
On some platforms, @code{malloc (n)} can succeed even if @code{n}
exceeds @code{PTRDIFF_MAX}.  Although this behavior is arguably
allowed by POSIX it can lead to behavior not defined by POSIX later,
so @code{malloc-posix} does not allow going over the limit.
@end itemize

Extension: Gnulib provides a module @samp{malloc-gnu} that substitutes a
@code{malloc} implementation that behaves more like the glibc implementation,
by fixing this portability problem:

@itemize
@item
@code{malloc (0)} returns @code{NULL} on success on some platforms:
AIX 7.2.
@end itemize