[Issue 19825] New: Memory corruption involving lazy variadic, stdio and json

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 25 17:23:01 UTC 2019


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

          Issue ID: 19825
           Summary: Memory corruption involving lazy variadic, stdio and
                    json
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bus_dbugzilla at semitwist.com

dub.sdl:
------------------------------
name "test"
dependency "std_data_json" version="==0.18.3"
------------------------------

main.d:
------------------------------
import std.stdio;
import stdx.data.json;

enum rawJson = `
{
        "rootPackage": "vibe-d",
        "targets": [
                {
                        "rootConfiguration": "vibe-core"
                }
        ]
}
`;

void yap(T...)(lazy T args)
{
        writeln(args);
}

struct Foo
{
        int a;
        string name;
}

Foo makeFoo()
{
        Foo foo;

        auto root = rawJson.toJSONValue;
        foo.name = root["rootPackage"].toString.idup;
        writeln(foo.name);
        yap(root["targets"][0]["rootConfiguration"]);

        return foo;
}

void main(string[] args)
{
        auto foo = makeFoo();
        writeln(foo.name); // Garbled output, then an exception
}
------------------------------

result:
------------------------------
$ dub -q
vibe-d
vibe-core
[...garbled data here...]uncaught exception
std.exception.ErrnoException@/home/nick/.dvm/compilers/dmd-2.085.0/linux/bin/../../src/phobos/std/stdio.d(2882):
Enforcement failed (Bad address)
----------------
/home/nick/.dvm/compilers/dmd-2.085.0/linux/bin/../../src/phobos/std/exception.d:515
@safe void
std.exception.bailOut!(std.exception.ErrnoException).bailOut(immutable(char)[],
ulong, scope const(char)[]) [0xf11be9a1]
/home/nick/.dvm/compilers/dmd-2.085.0/linux/bin/../../src/phobos/std/exception.d:436
@safe int
std.exception.enforce!(std.exception.ErrnoException).enforce!(int).enforce(int,
lazy const(char)[], immutable(char)[], ulong) [0xf11be921]
/home/nick/.dvm/compilers/dmd-2.085.0/linux/bin/../../src/phobos/std/stdio.d:2882
@safe void std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(scope
immutable(char)[]) [0xf11be81f]
/home/nick/.dvm/compilers/dmd-2.085.0/linux/bin/../../src/phobos/std/stdio.d:3806
@safe void std.stdio.writeln!(immutable(char)[]).writeln(immutable(char)[])
[0xf11be747]
src/main.d:41 _Dmain [0xf11a69d8]
Program exited with code -6
------------------------------

--


More information about the Digitalmars-d-bugs mailing list