[Issue 2975] copy - source may exceed target
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 26 13:25:50 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2975
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich at gmail.com
--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at 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: -------
More information about the Digitalmars-d-bugs
mailing list