Yet another leak in the sinking ship of @safe

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 18 11:01:14 PST 2016


On 2/18/16 1:50 PM, Jonathan M Davis wrote:
> On Thursday, 18 February 2016 at 18:41:25 UTC, Steven Schveighoffer wrote:
>> foo(void[] arr)
>> {
>>    void[] arr2 = [1234, 5678, 91011];
>>    arr[] = arr2[0 .. arr.length];
>> }
>
> Well, I'm not sure that that's actually not @safe. It's trying to
> interpret the void[] that's the problem. Certainly, you can convert T[]
> to void[] and pass it around all day without risking any memory
> corruption, so that should definitely be @safe, and I don't see how
> reducing the length of a void[] could actually cause memory corruption
> on its own. It's when you cast the void[] to something else that you
> risk things going south, and that's what needs to be @system. So, I'm
> not sure that there's actually any reason for your example code to not
> be @safe.

You don't need to cast to use the original.

void bar() @safe
{
    int *[] ptrs = new int*[1];
    foo(ptrs);
    *ptrs[0] = 5;
}

-Steve


More information about the Digitalmars-d mailing list