[PATCH] manual: Document deviation of realloc from C2x/N2464

Siddhesh Poyarekar siddhesh@sourceware.org
Wed Jun 14 16:21:21 GMT 2023


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


More information about the Libc-alpha mailing list