www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Escaping ref to stack mem sometimes allowed in safe?

reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
This compiles. Is it supposed to?

 safe ubyte[] foo()
{
	ubyte[512] buf;
	auto slice = buf[0..$];
	// Escaping reference to stack memory, right?
	return slice;
}

Or is the escaping reference detection not intended to be 100%? Or 
something else I'm missing?

Should I file   bugzilla?
Oct 14 2016
next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 10/14/16 4:49 PM, Nick Sabalausky wrote:
 This compiles. Is it supposed to?

  safe ubyte[] foo()
 {
     ubyte[512] buf;
     auto slice = buf[0..$];
     // Escaping reference to stack memory, right?
     return slice;
 }
Yes, this still is a problem, but Walter has a fix in the works. https://issues.dlang.org/show_bug.cgi?id=8838 This one is also fun: ubyte[512] foo(); ubyte[] x = foo(); // compiles, but never is correct. Ever. https://issues.dlang.org/show_bug.cgi?id=12625 -Steve
Oct 14 2016
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, October 14, 2016 16:49:44 Nick Sabalausky via Digitalmars-d-learn 
wrote:
 This compiles. Is it supposed to?

  safe ubyte[] foo()
 {
   ubyte[512] buf;
   auto slice = buf[0..$];
   // Escaping reference to stack memory, right?
   return slice;
 }

 Or is the escaping reference detection not intended to be 100%? Or
 something else I'm missing?

 Should I file   bugzilla?
It's a long-standing bug: https://issues.dlang.org/show_bug.cgi?id=8838 But Walter has been working on safety issues recently (particularly with regards to stuff like parameters escaping, because of DIP1000), so a fix should finally be coming. - Jonathan M Davis
Oct 17 2016