[Issue 14971] New: array.length -= x; should be checked for underflow when compiling without -release

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 27 08:03:27 PDT 2015


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

          Issue ID: 14971
           Summary: array.length -= x; should be checked for underflow
                    when compiling without -release
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: collin.reeser at gmail.com

For exactly the same reason that the index-out-of-bounds runtime checks are
useful for debugging purposes when compiling without the -release flag,
decrements on the array .length attribute should be checked during runtime for
underflow.

As it is now:

int main()
{
    int[] a = [];
    a.length--;
    return 0;
}

Will yield:

core.exception.OutOfMemoryError@(0)

This should instead be an error message along the lines of the
index-out-of-bounds exception that indicates what the problem actually is.

This is related to Issue 3933 from 2010 (there's still no line number on the
error, which goes a long way to making this issue less important).

--


More information about the Digitalmars-d-bugs mailing list