DMD 1.004 release
Jordan Miner
jminer2613 at no.spam.students.pcci.edu
Sat Jan 27 13:35:23 PST 2007
Here is a problem I've found in post-1.00 versions.
I have this unittest in my library:
unittest {
char[] c = "Computer";
ArrayCopy!(char)(c, 3, c, 2, 4);
assert(c == "Coputeer");
c = "Computer";
ArrayCopy!(char)(c, 2, c, 3, 4);
assert(c == "Commputr");
}
I have not changed the ArrayCopy function for months and when I updated from 1.00, the second assert started failing. After some work, I tracked down the problem.
This line:
c = "Computer";
is not doing anything. I put printf(c) right after that assignment, and it prints "Coputeer".
I didn't test 1.002, but it is broken in 1.001, 1.003, and 1.004.
(I love built-in unittests)
The ArrayCopy function:
void ArrayCopy(T)(T[] srcData, uint srcStart, T[] destData, uint destStart, uint length) {
if((srcData is destData && srcStart == destStart) || length == 0)
return;
if(srcStart > destStart) {
//copy forward
for(int i = 0; i < length; ++i)
destData[destStart + i] = srcData[srcStart + i];
} else {
//copy reverse
for(int i = length-1; i >= 0; --i)
destData[destStart + i] = srcData[srcStart + i];
}
}
More information about the Digitalmars-d-announce
mailing list