C-Allocators: Mention reallocarray for safe array allocation

Signed-off-by: Daiki Ueno <dueno@redhat.com>
This commit is contained in:
Daiki Ueno 2020-10-12 10:10:07 +02:00 committed by huzaifas
parent 4d3fbd6273
commit e6baf3d2fb

View file

@ -118,6 +118,12 @@ to allocate an array of `n` elements of type
greater than `((size_t) -1) / sizeof(T)`. See
<<sect-Defensive_Coding-C-Arithmetic>>.
GNU libc provides a dedicated function `reallocarray` that allocates
an array with those checks performed internally. However, care must
be taken if portability is important: while the interface originated
in OpenBSD and has been adopted in many other platforms, NetBSD
exposes an incompatible behavior with the same interface.
[[sect-Defensive_Coding-C-Allocators-Custom]]
=== Custom Memory Allocators