[Issue 10516] New: Array length is not checked when array is a manifest constant

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 30 18:38:32 PDT 2013


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

           Summary: Array length is not checked when array is a manifest
                    constant
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-30 18:38:31 PDT ---
-----
void main()
{
    enum HexSize = 5;

    // note: smaller initializer count
    enum char[HexSize] srcHex = "1234";

    char[HexSize] tgtHex = "12345";

    // should error with: lengths don't match for array copy
    assert(tgtHex[0 .. 4] == srcHex);
}
-----

$ dmd test.d
> core.exception.AssertError at test(11): Assertion failure

The problem here is that the runtime allowed the left-hand side and right-hand
side arrays to be compared even though their lengths do not match.

If you convert the source array from a manifest constant into a regular array
(by removing enum) then the error is proper:

-----
void main()
{
    enum HexSize = 5;

    // note: smaller initializer count
    /* enum */ char[HexSize] srcHex = "1234";  

    char[HexSize] tgtHex = "12345";

    assert(tgtHex[0 .. 4] == srcHex);
}
-----

$ dmd test.d
> object.Error: lengths don't match for array copy, 5 = 4

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list