www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23438] New: leaking address of stack

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

          Issue ID: 23438
           Summary: leaking address of stack
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

As reported by Timon Gehr:

int global;
int* escaped;
void qux() safe{
    int stack=1337;
    int* foo(return scope int* x) safe{
        int* bar(return scope int* y) safe{
            return x;
        }
        escaped=bar(&global);
        return x;
    }
    foo(&stack);
}
void main() safe{
    qux();
    import std.stdio;
    version(THRASH_STACK) writeln("thrashing stack");
    writeln(*escaped);
}

--
Oct 26 2022