[Issue 18575] New: making delegate from member function can lead to unsafe code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 7 23:34:39 UTC 2018


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

          Issue ID: 18575
           Summary: making delegate from member function can lead to
                    unsafe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

As reported by Tomer Filiba:

    @safe:

    struct S {
    @safe:
        int x;

        auto foo() {return &bar;}
        void bar() {x = 999;}
    }

    auto f() {
        auto s = S(100);
        return s.foo();
    }

    void main() {
        auto dg = f();
        dg();     // i now have a delegate that will write 999 to some random
stack location
    }

--


More information about the Digitalmars-d-bugs mailing list