www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1741] New: crash on associative array with static array as index type

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: georg 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)].


-- 
Dec 18 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1741


jason spashett.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason spashett.com





This still occurs with dmd version 1.028

user vm-fruitbat:~$ dmd -g t.d
user vm-fruitbat:~$ gdb t
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run
Starting program: /home/user/t
[Thread debugging using libthread_db enabled]
[New Thread -1209919824 (LWP 12717)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1209919824 (LWP 12717)]
0x08053906 in _D3std8typeinfo5ti_Ag11TypeInfo_Ag7getHashMFPvZk ()
(gdb) bt


Die: DW_TAG_<unknown> (abbrev = 6, offset = 505)
        has children: FALSE
        attributes:
                DW_AT_byte_size (DW_FORM_data1) constant: 4
                DW_AT_type (DW_FORM_ref4) constant ref: 340 (adjusted)
                DW_AT_containing_type (DW_FORM_ref4) constant ref: 486
(adjusted)
Dwarf Error: Cannot find type of die [in module /home/user/t]


-- 
Apr 02 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1741


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed dmd 1.029 and 2.013


-- 
May 11 2008