[musl] Re: realloci(): A realloc() variant that works in-place

Thiago Macieira thiago@macieira.org
Sat Nov 1 14:55:06 GMT 2025


On Saturday, 1 November 2025 06:38:41 Pacific Daylight Time Thorsten Glaser 
wrote:
> Paul Eggert dixit:
> > You're right I'm not saying that. All I'm saying is that when
> > R=realloc(P,N) succeeds, you can assume that you can adjust old
> > pointers into the object addressed by P by adding R-P to them. The C
> > standard says this results in undefined behavior; all that we need to
> > do is fix the C standard to say it's well-defined (because it is on
> > practical platforms).
> 
> That won’t fix old standard versions retroactively though.
> 
> You can already do this now by casting the old pointer to
> ptraddr_t (ifdef __CHERI__) / uintptr_t (else) before the
> realloc and the new one afterwards for comparison and the
> arithmetic.

Strictly speaking, you need core language changes in both C and C++ to make 
the the arithmetic in question valid, instead of UB. I wouldn't hold my hopes 
up, in spite of just "works everywhere".

Anyway, I now understand Paul's proposal. It is orthogonal to realloci(). I am 
not sure if I would support it, but I wouldn't oppose it in *addition* to 
realloci(). I would definitely oppose it if it is *instead of* realloci().

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 870 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251101/cd6cb7cc/attachment-0001.sig>


More information about the Libc-alpha mailing list