diff mbox series

manual: Document deviation of realloc from C2x/N2464

Message ID 20230614142855.1535558-1-siddhesh@sourceware.org
State New
Headers show
Series manual: Document deviation of realloc from C2x/N2464 | expand

Commit Message

Siddhesh Poyarekar June 14, 2023, 2:28 p.m. UTC
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(+)

Comments

Florian Weimer June 14, 2023, 3:54 p.m. UTC | #1
* Siddhesh Poyarekar:

> 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.

There is no ISO C2x standard, and there will never be.

I think it makes sense to add a sentence at the end of the section that
behavior of realloc varies between implementations for zero arguments,
without a standard reference, but mention the {Replace malloc} node
(that is, an interposed malloc may behave differently).

Thanks,
Florian
Siddhesh Poyarekar June 14, 2023, 4:21 p.m. UTC | #2
On 2023-06-14 11:54, Florian Weimer wrote:
> * Siddhesh Poyarekar:
> 
>> 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.
> 
> There is no ISO C2x standard, and there will never be.

We refer to it in arith.texi FWIW, which emboldened me to add that 
reference:

manual/arith.texi:NaN is specified in C2x; the value was unspecified in 
TS 18661.)

> I think it makes sense to add a sentence at the end of the section that
> behavior of realloc varies between implementations for zero arguments,
> without a standard reference, but mention the {Replace malloc} node
> (that is, an interposed malloc may behave differently).

Fair enough, v2 coming up.

Thanks,
Sid
diff mbox series

Patch

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