www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20862] New: Segfault on repeated GC.qalloc calls

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

          Issue ID: 20862
           Summary: Segfault on repeated GC.qalloc calls
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

The following code causes a segfault in the GC (tested on 2.092.0):

===================================================
void main()
{
    import core.memory;

    string[] arr;

    foreach (_; 0 .. 3) // first two iterations pass
    {
        immutable len = arr.length;

        auto bi = GC.qalloc(string.sizeof);
        arr = (cast(string*) bi.base)[0 .. len];

        arr = arr.ptr[0 .. len + 1];
        arr[] = [];
    }
}
===================================================

gdb:

Program received signal SIGSEGV, Segmentation fault.
0x0000000008067be6 in
_D2gc4impl12conservativeQw3Gcx10smallAllocMFNbmKmkxC8TypeInfoZPv ()

--
May 24 2020