Hi,

There seems to be a bug allocating large dynamic arrays in a 64-bit aware dmd (v2.062). Apparently, the size argument makes a trip through 32-bit ptrdiff_t land or something like that:

unittest
{
    immutable size_t size = 3 * 1024 * 1024 * 1024;
    auto data = new byte[size]; // compiler error:
// file.d(line): Error: negative array index 18446744072635809792LU
}

unittest
{
    immutable size_t size = 4 * 1024 * 1024 * 1024;
auto data = new byte[size]; // fails silently, zero length array
    assert(data.length != 0); // assert error
}

Have you seen this before? I can open a bug, but just checking.

In any case, I don't understand why the compiler doesn't complain about overflows at compile time:

unittest
{
size_t s1 = uint.max + 1; // shouldn't it complain with -m32 flag? it does not.
    assert(s1 != 0); // fails for -m32, as expected
uint s2 = 0xFFFFFFFF + 1; // shouldn't it complain? it does not.
}

Regards,
Luís

Reply via email to