[Issue 1741] New: crash on associative array with static array as index type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 18 05:07:56 PST 2007


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

           Summary: crash on associative array with static array as index
                    type
           Product: D
           Version: 1.023
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: georg at op-co.de


The associative array implementation causes a segmentation fault when used with
a static array as the key type.
The nice guys on #D helped me to trace the problem to the following point:

The implementation crashes in uint
std.typeinfo.ti_Ag.TypeInfo_Ag.getHash(void*), which is actually meant for
dynamic arrays, so it seems the wrong TypeInfo is referenced, and thus the
memory access in getHash() fails.

The following code triggers the problem for me (you have to initialize key with
!=0):

int main() {
    ubyte[4] key = 23;
    int[ubyte[4]] aa;
    aa[key] = 42;
    /* this point is never reached */
    return 0;
}

A workaround is to use dynamic arrays (less efficient because of an added level
of redirection) or to encapsulate the static array into a struct (less
readable, but working).

The problem can also be reproduced with gdc [gcc version 4.1.3 20071209
(prerelease gdc 0.25 20071124, using dmd 1.022) (Debian 0.25-4.1.2-18)].


-- 



More information about the Digitalmars-d-bugs mailing list