[Issue 14005] core.exception.InvalidMemoryOperationError@(0) during byLine

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jan 18 20:31:26 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14005

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com

--- Comment #1 from ag0aep6g at gmail.com ---
Reduced:

----
import core.memory: GC;
void main()
{
    /* First line. Exact length doesn't matter. */
    auto firstLineLength = 260;
    auto buf = new char[firstLineLength];

    /* Second line. Must not be about as long as the block allocated for the
first line. */
    auto firstBlockSize = GC.sizeOf(buf.ptr);
    buf = buf.ptr[0 .. firstBlockSize];
    auto secondLineLength = firstBlockSize; /* no good */
    version(none) auto secondLineLength = firstBlockSize - 1; /* no good */
    version(none) auto secondLineLength = firstBlockSize - 2; /* ok */
    buf = buf.ptr[0 .. secondLineLength];

    /* popFront the second line. */
    assumeSafeAppend(buf); /* core.exception.InvalidMemoryOperationError@(0) */
}
----

I guess the size returned by GC.sizeOf includes some internal data. Then
std.stdio.readlnImpl is wrong to assume that it can use all of it.

--


More information about the Digitalmars-d-bugs mailing list