[Issue 5270] New: Using a scope delegate allows memory corruption in safe mode
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 24 09:06:04 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5270
Summary: Using a scope delegate allows memory corruption in
safe mode
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid, spec
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bugzilla at kyllingen.net
--- Comment #0 from Lars T. Kyllingstad <bugzilla at kyllingen.net> 2010-11-24 09:04:42 PST ---
The following program compiles and runs without error. Memory corruption
happens in bar() because the context for the delegate stored in globalDg never
gets copied to the heap, due to the 'scope' storage class being used in call().
@safe:
void delegate() globalDg;
void call(scope void delegate() @safe dg)
{
dg();
// Don't tell anyone, but I'm saving this for later ;)
globalDg = dg;
}
void foo()
{
int i;
void izero() { i = 0; }
call(&izero);
assert (i == 0);
}
void bar()
{
int x = 123;
// Simply calling some function cannot possibly
// do anything to x...
globalDg();
// ...or can it?
assert (x == 0);
}
void main()
{
foo();
bar();
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list