[Issue 22171] New: Segfault in generated __xtoHash, related to unions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 2 19:40:16 UTC 2021


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

          Issue ID: 22171
           Summary: Segfault in generated __xtoHash, related to unions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kinke at gmx.net

```
module current;

class C
{
    // needed for `S` to get a `__xtoHash`
    int opCmp(const C rhs) const { return 1; }
}

struct S
{
    C c;
    union
    {
        string str;
        S[] ss;
    }
    ulong[10_000] large;
}

void main()
{
    S s = {str:
"wsdpfijsdpfijspfklmxcö,,msdfkjsmndfpösdmnfpoisdmfüosijfposidj"};
    const h = typeid(S).getHash(&s);
}
```

The code above segfaults with DMD v2.097.1, with the following backtrace:

#0  0x00005555555a9da5 in object.TypeInfo_Class.getHash(scope const(void*))
const ()
#1  0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*))
const ()
#2  0x00005555555a8d1f in _D7current1S9__xtoHashFNbNeKxSQBcQxZm ()
#3  0x00005555555aa38e in object.TypeInfo_Struct.getHash(scope const(void*))
const ()
#4  0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*))
const ()
#5  0x00005555555ab24c in object.getArrayHash(scope const(TypeInfo), scope
const(void*), const(ulong)) ()
#6  0x00005555555a92c4 in object.TypeInfo_Array.getHash(scope const(void*))
const ()
#7  0x00005555555aa6e3 in object.TypeInfo_Const.getHash(scope const(void*))
const ()
#8  0x00005555555a8d6c in _D7current1S9__xtoHashFNbNeKxSQBcQxZm ()
#9  0x00005555555aa38e in object.TypeInfo_Struct.getHash(scope const(void*))
const ()
#10 0x00005555555a8e17 in D main ()

I guess it's trying to compute the hashes of *all* members, so both `str` and
`ss`, with `ss` likely representing invalid memory if the `str` member with way
smaller element size (char vs. S) was set.

--


More information about the Digitalmars-d-bugs mailing list