[Issue 24162] Another example of why @safe is broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 26 07:43:04 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24162

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m

--- Comment #1 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
Why do you think that it modifies random memory? If a dynamic array is
reallocated, that has no effect whatsoever on the block of memory that it
referred to before. A new block of memory is allocated, the portions of the old
block of memory that the dynamic array refers to are copied into the new block
of memory, and the dynamic array's pointer is changed to point to the new block
of memory. However, the old block of memory is still around. The GC still knows
about it, and it's still valid, so it won't be collected until nothing refers
to it any longer. So, x can continue to refer to that block of memory and
access it even though arr no longer does. Sure, you don't actually have access
to what x changed once f returns, but nothing unsafe occurred.

--


More information about the Digitalmars-d-bugs mailing list