[PATCH] manual: Document deviation of realloc from C2x/N2464
Siddhesh Poyarekar
siddhesh@sourceware.org
Wed Jun 14 14:28:55 GMT 2023
Explicitly note that the realloc behaviour chosen in glibc is deliberate
and well defined and suggest that strictly compliant code should avoid
passing zero to realloc.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
manual/memory.texi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/manual/memory.texi b/manual/memory.texi
index 5781a64f35..7697a10f72 100644
--- a/manual/memory.texi
+++ b/manual/memory.texi
@@ -832,6 +832,11 @@ space is available. The value of @code{realloc} is the new address of the
block. If the block needs to be moved, @code{realloc} copies the old
contents.
+The ISO C2x standard regards a zero value for @var{newsize} as undefined
+through N2464, so code that aims to be strictly compliant should avoid passing
+zero as @var{newsize} to @code{realloc}. @Theglibc{} behavior however is well
+defined below.
+
If you pass a null pointer for @var{ptr}, @code{realloc} behaves just
like @samp{malloc (@var{newsize})}.
Otherwise, if @var{newsize} is zero
--
2.40.1
More information about the Libc-alpha
mailing list