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


Andrej Mitrovic <andrej.mitrov...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrov...@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-05-26 
13:21:31 PDT ---
This will be caught in non-release builds, simply because copy calls put(),
which calls front(target), where front() has this assert:
  assert(a.length, "Attempting to fetch the front of an empty array");

The assert goes away in release, which means if you compile the following with
-release the enforce will pass since memory will get overwritten:

import std.algorithm;
import std.exception;

void main()
{
    // compile with -release
    auto a = [1, 2, 3, 4, 5];
    int[] b = new int[3];

    copy(a, b);
    enforce(b[3] == 4);  // oops..
}

If we add your changes it means debug builds will end up doing double checks,
once in copy() where it would check for "!target.empty" (which I think should
actually be expression "target.length"), and once in the call to front() by the
put() function.

I'm not sure what, if anything should be done about this. Personally I would
only expect the possibility of this kind of memory corruption if I pass the
-noboundscheck switch. Anyone else care to share their opinion?

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

Reply via email to