Bug 18575 – making delegate from member function can lead to unsafe code

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-07T23:34:39Z
Last change time
2018-03-09T18:25:19Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=17448

Comments

Comment #0 by bugzilla — 2018-03-07T23:34:39Z
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 }
Comment #1 by bugzilla — 2018-03-09T06:45:35Z
Comment #2 by github-bugzilla — 2018-03-09T18:25:19Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/75966dac262efb407bfedc6e1ed993802d95c7c8 fix Issue 18575 - making delegate from member function can lead to unsafe code https://github.com/dlang/dmd/commit/51087a02078585204377d8dad1b029f50bfa407e Merge pull request #7989 from WalterBright/fix18575 fix Issue 18575 - making delegate from member function can lead to un…