Gnulib module: realloc-posix
Portability problems fixed by Gnulib:
ENOMEMon some platforms: mingw, MSVC 14.
realloc (p, n)can succeed even if
PTRDIFF_MAX. Although this behavior is arguably allowed by POSIX it can lead to behavior not defined by POSIX later, so
realloc-posixdoes not allow going over the limit.
Without the ‘realloc-gnu’ module described below, it is not portable
realloc with a size of 0. With a
NULL pointer argument, this is the same ambiguity as
on whether a unique zero-size object is created. With a non-NULL
p, C17 says that it is implementation-defined
realloc (p, 0) frees
Behavior varies on whether
realloc (p, 0) always frees
and successfully returns a null pointer, or always
fails and leaves
p valid, or usually succeeds and returns a
unique zero-size object; a program not suspecting these variations in
semantics will leak memory (either the still-valid
p, or the
non-NULL return value).
Extension: Gnulib provides a module ‘realloc-gnu’ that substitutes a
realloc implementation that behaves more like the glibc implementation.
It fixes these portability problems:
realloc (NULL, 0)returns
NULLon success on some platforms: AIX 7.2.
realloc (p, 0)with non-null
pmight not free
p, or might clobber
errno, or might not return