[Issue 14979] [REG2.068] Wrong tempCString result on x64 with ternary operator

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Aug 30 06:51:23 PDT 2015


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

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
OK, I confirmed this is actually a dup of issue 14696.

To reproduce the issue, we need to specify -unittest. By that, tempCString will
make the buffer size smaller and the used heap memory will be destructed at the
wrong timing.

auto tempCString(To = char, From)(From str)
    if (isSomeChar!To && (isInputRange!From || isSomeString!From) &&
        isSomeChar!(ElementEncodingType!From))
{
    ...
    static struct Res
    {
        ...

    private:
        To* _ptr;
        version (unittest)
        {
            enum buffLength = 16 / To.sizeof;
            // smaller size to trigger reallocations
        }
        else
        {
            enum buffLength = 256 / To.sizeof;
            // production size
        }

        To[256 / To.sizeof] _buff;  // the 'small string optimization'

--


More information about the Digitalmars-d-bugs mailing list