| 
  | 
Message-ID: <CANv4PNnd6maoR6yMZyRZ7CWAqdKYXQN6QPQyEdu7Szmu+PeZVg@mail.gmail.com>
Date: Fri, 31 Oct 2025 19:46:23 -0400
From: Morten Welinder <mwelinder@...il.com>
To: musl@...ts.openwall.com
Cc: Alejandro Colomar <alx@...nel.org>, Thorsten Glaser <tg@...bsd.de>, libc-alpha@...rceware.org, 
	"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>
Subject: Re: Re: realloci(): A realloc() variant that works in-place
> 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.
With a bit of effort you can travel from UB to implementation-defined.
The trick is to
use the pointer before the realloc.  Something like
      sprintf(buffer1, "%p", (void *)p);
      q = realloc(p, newsize);
      sprintf(buffer2, "%p", (void *)q);
      int moved = strcmp(buffer1, buffer2) != 0;
Clearly not UB.  I just can't convince myself that the standards
actually guarantee that a changed pointer doesn't have the same %p
representation.
I don't know of any platforms where a collision would actually happen, though.
M.
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.