mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-09-05 13:11:33 +00:00
Also, port better to non-glibc, and in documentation update the list of platforms needing a fix. This includes 32-bit platforms using AddressSanitizer, unfortunately. * m4/malloc.m4 (gl_CHECK_MALLOC_PTRDIFF): Invoke gl_MUSL_LIBC. musl is safe, as is FreeBSD 11+, NetBSD 8+, OpenBSD 5.6+, AIX, Microsoft Windows. However, the AddressSanitizer is unsafe.
61 lines
2.0 KiB
Plaintext
61 lines
2.0 KiB
Plaintext
@node reallocarray
|
|
@subsection @code{reallocarray}
|
|
@findex reallocarray
|
|
|
|
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/reallocarray.html}
|
|
|
|
Documentation:
|
|
@itemize
|
|
@item
|
|
@ifinfo
|
|
@ref{Changing Block Size,,Changing the Size of a Block,libc},
|
|
@end ifinfo
|
|
@ifnotinfo
|
|
@url{https://www.gnu.org/software/libc/manual/html_node/Changing-Block-Size.html},
|
|
@end ifnotinfo
|
|
@item
|
|
@uref{https://www.kernel.org/doc/man-pages/online/pages/man3/reallocarray.3.html,,man reallocarray}.
|
|
@end itemize
|
|
|
|
Gnulib module: reallocarray
|
|
@mindex reallocarray
|
|
|
|
Portability problems fixed by Gnulib:
|
|
@itemize
|
|
@item
|
|
This function is missing on many platforms:
|
|
glibc 2.25, macOS 14, FreeBSD 10, NetBSD 7, OpenBSD 5.5, Minix 3.3.0, AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 1.7.x, mingw, MSVC 14, Android 9.0.
|
|
|
|
@item
|
|
On some platforms, when the function fails it might set @code{errno}
|
|
to @code{EAGAIN} instead of to @code{ENOMEM}. Although POSIX allows
|
|
@code{EAGAIN}, the @code{reallocarray} module insists on @code{ENOMEM}
|
|
which also conforms to POSIX and is GNU-compatible:
|
|
Solaris 11.4.
|
|
|
|
@item
|
|
On some 32-bit platforms, @code{reallocarray (p, n, s)} can succeed even if
|
|
multiplying @code{n} by @code{s} would exceed @code{PTRDIFF_MAX},
|
|
which can lead to undefined behavior later:
|
|
AddressSanitizer of gcc 16.1 or clang 22.1, glibc 2.29, Solaris 11.4.
|
|
|
|
Although this behavior is arguably
|
|
allowed by POSIX it is not compatible with GNU and
|
|
can lead to behavior not defined by POSIX later,
|
|
so @code{realloc-posix} does not allow going over the limit.
|
|
|
|
@item
|
|
It is not portable to call
|
|
@code{reallocarray (p, n, s)} when either @code{n} or @code{s} is zero,
|
|
as @code{reallocarray} has the same issues with zero sizes
|
|
that @code{realloc} does. @xref{realloc}.
|
|
@end itemize
|
|
|
|
Portability problems not fixed by Gnulib:
|
|
@itemize
|
|
@item
|
|
When not growing an already-allocated region,
|
|
@code{reallocarray}, like @code{realloc}, can fail and return a null pointer:
|
|
glibc 2.44 and probably other platforms.
|
|
@end itemize
|