Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <vlbnbah67jpldqnuuaqjxfgmxude4ry7qgvaqfc3ylbhi5imqm@wqpneemwezqq>
Date: Fri, 31 Oct 2025 17:22:40 +0100
From: Alejandro Colomar <alx@...nel.org>
To: Thiago Macieira <thiago@...ieira.org>
Cc: libc-alpha@...rceware.org, musl@...ts.openwall.com, 
	"A. Wilcox" <AWilcox@...cox-tech.com>, Lénárd Szolnoki <cpp@...ardszolnoki.com>, 
	Collin Funk <collin.funk1@...il.com>, Arthur O'Dwyer <arthur.j.odwyer@...il.com>, 
	Jonathan Wakely <jwakely@...hat.com>, "Paul E. McKenney" <paulmck@...nel.org>, 
	Alejandro Colomar <alx@...nel.org>
Subject: Re: Re: realloci(): A realloc() variant that works in-place

Hi Thiago, Thorsten, Paul,

On Fri, Oct 31, 2025 at 09:02:42AM -0700, Thiago Macieira wrote:
> On Friday, 31 October 2025 08:45:09 Pacific Daylight Time Thorsten Glaser 
> wrote:
> > >In C, I've sometimes seen programmers trying to check if realloc(3)
> > >moved or not, to skip some work.  That's a micro-optimization that I've
> > >never written myself, so I won't defend it.  But for some reason, some
> > >programmers keep wanting to do it.
> > 
> > Huh. That one if is probably more effort than just doing the
> > arithmetics always… if it’s not actually UB…
> 
> The conclusion among C++ developers is that using the previous pointer in any 
> way is UB. Therefore, you simply cannot know if the area was moved or not.

Yes, it is UB.  realloc(3) zaps old pointers.  Paul McKenney is
proposing to not zap the old pointer in some cases, but with current
ISO C, it is UB.

I don't remember well the details of what Paul told me in Paris, so I've
CCed him, in case he can clarify, or maybe if he has some reasons to
defend wanting to use the old pointer.

Paul, for context, this is a discussion for adding a function

	int realloci(void *p, size_t n);

that changes the size of a memory block without moving it.  (And thus,
fails rather often, for some implementations of allocators.)

Thiago, if you need this, it would also be useful to clarify what it
would be useful for, and numbers if the micro-optimizations are
important for you.

Here's the start of the thread, for anyone reading new:
<https://inbox.sourceware.org/libc-alpha/tzrznth5ng3qukc4dlym5woctbppcabjglsxgfnfvdrd45rr5d@573xvnl5twv6/T/#m625715f975b04cd7dd3d96276a7a83ace9f40d52>


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.