[Issue 19042] New: Chunking a padRight'ed range leads to range violations
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 29 18:24:39 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19042
Issue ID: 19042
Summary: Chunking a padRight'ed range leads to range violations
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: asumface at gmail.com
The following code exhibits a range violation:
import std.stdio;
import std.range;
import std.conv;
void main()
{
pragma(msg, [2,5,13].padRight(42, 10).chunks(5).to!string);
}
Compiler output:
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(12811): Error:
slice [5..3] exceeds array bounds [0..3]
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(12811):
called from here: Result(null, 0, 0LU, 0LU, 0LU).this(b <= this.data.length ?
this.data[a..b] : this.data[a..this.data.length], this.element, b - a)
/dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d(1743):
called from here: r.opSlice(n, __dollar)
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(7704):
called from here: popFrontN(this._source, this._chunkSize)
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(3299): called from
here: val.popFront()
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(4127): called from
here: formatRange(w, val, f)
/dlang/dmd/linux/bin64/../../src/phobos/std/format.d(1845): called from
here: formatValueImpl(w, val, f)
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(151): called from
here: formatValue(w, src, f)
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(1018): called from
here: toStr(value)
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(222): called from
here: toImpl(_param_0)
onlineapp.d(7): called from here: to(chunks(padRight([2, 5, 13], 42,
10LU), 5LU))
onlineapp.d(7): while evaluating pragma(msg, chunks(padRight([2, 5, 13],
42, 10LU), 5LU).to!string)
The problem occurs almost indepentently from the supplied arguments and is not
restricted to compile-time evaluation, the only requirement that I could
determine is that padRight needs to extend its input by at least one element.
Replacing chunks with evenChunks results in the same error. padLeft does not
appear to be affected by this issue.
It can be reproduced in all versions since the introduction of padRight
(2.072).
--
More information about the Digitalmars-d-bugs
mailing list