[Issue 23440] closure over typesafe variadic or scope array passes safe though leads to stack corruption
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Jun 27 21:31:37 UTC 2023
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23440
--- Comment #5 from Adam D. Ruppe <destructionator at gmail.com> ---
user on the discord posted this which also seems kinda similar
import std;
auto makeClosure(ref int n) @safe
{
    return ref () => n;
}
auto escapeClosure() @safe
{
    int n = 123;
    return makeClosure(n);
}
void clobberStack() @safe
{
    ubyte[4096] a;
}
void main() @safe
{
    auto dg = escapeClosure();
    pragma(msg,typeof(dg));
    clobberStack();
    assert(dg() == 123); // kaboom
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list