www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19042] New: Chunking a padRight'ed range leads to range


          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 puremagic.com
          Reporter: asumface 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]
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)
called from here: r.opSlice(n, __dollar)
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

Jun 29 2018