1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-10 04:43:00 +03:00
Files
gnulib/doc/posix-functions/reallocarray.texi
Paul Eggert d884e6fc4a realloc-posix: realloc (..., 0) now returns nonnull
* lib/realloc.c (rpl_realloc): Simplify and tune by using
HAVE_REALLOC_0_NONNULL and HAVE_MALLOC_PTRDIFF, and
by having just one call to realloc instead of two.
* lib/reallocarray.c (reallocarray): Simplify and tune
by delegating the zero case to the revised realloc.
* m4/eealloc.m4 (_AC_FUNC_REALLOC_IF): Since only eealloc uses
this macro now, move its definition here ...
* m4/realloc.m4: ... from here.
(gl_FUNC_REALLOC_0_NONNULL): Also check that realloc (p, 0)
returns nonnull.  Require gl_FUNC_REALLOC_POSIX.
Define HAVE_REALLOC_0_NONNULL.
* m4/reallocarray.m4 (gl_FUNC_REALLOCARRAY):
Also replace reallocarray if it returns a null pointer for size zero.
* modules/eealloc (Files): Remove m4/realloc.m4.
* modules/realloc-posix (Depends-on): Add extensions-aix.
* modules/reallocarray (Files): Add m4/realloc.m4.
2024-11-04 21:40:18 -08:00

45 lines
1.3 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, @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:
FreeBSD 13, NetBSD 9, OpenBSD 6, musl 1.2.
@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
@end itemize