- NetBSD Manual Pages
REALLOCARRAY(3) NetBSD Library Functions Manual REALLOCARRAY(3)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
reallocarray -- reallocate memory for an array of elements checking for
reallocarray(void *ptr, size_t nmemb, size_t size);
The reallocarray() function reallocates the pointer ptr to a size appro-
priate to handle an allocation of nmemb elements in an array where each
of the array elements is size bytes using realloc(3) and making sure that
overflow does not happen in the multiplication of ``nmemb * size''.
This function is provided for source compatibility with OpenBSD and its
use is discouraged in preference to reallocarr(3).
The reallocarray() function will return NULL if there was overflow or if
realloc(3) failed setting errno to EOVERFLOW or preserving the value from
malloc(3), realloc(3), reallocarr(3)
reallocarray() is an OpenBSD extension.
The reallocarray() function first appeared in OpenBSD 5.6.
reallocarray() was redesigned in NetBSD 8 as reallocarr(3). For compati-
bility reasons it's available since NetBSD 8 in the _OPENBSD_SOURCE
The reallocarray() function was designed to facilitate safe, robust pro-
gramming and overcome the shortcomings of the malloc(3) and realloc(3)
functions by centralizing the overflow check in the multiplication of
nmemb and size.
There are still portability issues (it does not solve the 0 sized alloca-
tion return ambiguity in the C standard: does reallocarray() return NULL
or a unique pointer to memory that cannot be accessed? Does a NULL mean
that an error occurred, and can someone check errno in that case to find
out what happened?).
For this reason NetBSD decided to go with an alternative implementation,
and created reallocarr(3).
NetBSD 9.3 February 5, 2015 NetBSD 9.3