[Issue 9612] std.range.Cycle.opSlice tests on the bounds are missing
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 27 15:26:59 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9612
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
CC| |bearophile_hugs at eml.cc
Summary|cycle() and opSlice |std.range.Cycle.opSlice
| |tests on the bounds are
| |missing
--- Comment #1 from bearophile_hugs at eml.cc 2013-02-27 15:26:58 PST ---
I was about to file this bug myself, this is the text I was going to use:
This code:
void main() {
auto a = [0,1,2,3,4,5,6,7,8,9][5 .. 2];
}
Gives the correct compile-time error:
temp3.d(2): Error: array slice [5 .. 2] is out of bounds
temp3.d(2): Error: array slice [5 .. 2] is out of bounds
While this gives no compile-time nor run-time errors:
import std.stdio: writeln;
import std.range: iota, cycle, take;
void main() {
iota(10).cycle()[5 .. 2].take(4).writeln();
}
And prints (DMD 2.063alpha):
[5, 6, 7, 8]
The opSlice of cycle() lacks pre-conditions or tests, and there are not enough
unittests to catch this bug:
auto opSlice(size_t i, size_t j)
{
auto retval = this.save;
retval._index += i;
return takeExactly(retval, j - i);
}
j - i is positive because those numbers are unsigned, and because D lacks
run-time errors for integral overflows:
import std.stdio;
struct Foo {
auto opSlice(size_t i, size_t j) {
writeln(j - i);
}
}
void main() {
Foo f;
f[5 .. 2];
}
Output:
4294967293
Maybe there is a need to run something similar to QuickCheck on Phobos:
http://en.wikipedia.org/wiki/QuickCheck
--
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