[Issue 8658] New: Passing large structs to function b value causes stack corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 14 01:41:21 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8658

           Summary: Passing large structs to function b value causes stack
                    corruption
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: r.sagitario at gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario at gmx.de> 2012-09-14 01:41:33 PDT ---
If the arguments passed to a function exceed 64kB the stack gets corrupted.
Compiling and running this code without optimizations leads to a crash:

struct S
{
    int[16385] a;
}

void foo(S s)
{
}

void main()
{
    S s;
    for(int i = 0; i < 100; i++)
        foo(s);
}

This is caused by the frame pointer cleanup only popping the lower 16 bit of
the used stack size:

_D4test3fooFS4test1SZv  comdat
        assume  CS:_D4test3fooFS4test1SZv
                ret     4
_D4test3fooFS4test1SZv  ends

[Actually I never meant to do this, it happened because I thought I was passing
a class reference.]

-- 
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