www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10124] New: Array length increases on subtraction of a big number instead of throwing RangeError

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

           Summary: Array length increases on subtraction of a big number
                    instead of throwing RangeError
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com
            Blocks: 10123


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-05-20
15:52:02 MSD ---
This code runs fine but should fail in runtime:
---
void main()
{
    int[] arr;
    arr.length -= size_t.max; // Let's subtract a very big number
    assert(arr.length == 1); // Passes!
}
---

Also there is a question what to do with `arr.length -= -1`? I'd like this code
to be rejected as incorrect mixed signed/unsigned operation (see also Issue
259).

This is a compiler bug as dmd just calls `_d_arraysetlengthT` without any
information about operation type. I.e. it works like `arr.length = arr.length -
size_t.max`.

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