← Back to index
|
Original Bugzilla link
Bug 19825 – Memory corruption involving lazy variadic, stdio and json
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-04-25T17:23:01Z
Last change time
2019-05-25T05:31:59Z
Keywords
wrong-code
Assigned to
Suleyman Sahmi (سليمان السهمي)
Creator
Nick Sabalausky
Comments
Comment #0
by bus_dbugzilla — 2019-04-25T17:23:01Z
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 ------------------------------
Comment #1
by razvan.nitu1305 — 2019-04-27T08:23:12Z
This looks like a phobos error, not a dmd one.
Comment #2
by ag0aep6g — 2019-04-27T15:13:04Z
Reduced test case: ---- import std.stdio; struct JSONValue { TaggedUnion payload; } struct TaggedUnion { size_t[2] m_data; int m_kind; JSONValue opIndex(size_t i) { return JSONValue(); } } void yap(lazy JSONValue arg) { writeln(arg); } struct Foo { int a; string name; } Foo makeFoo() { JSONValue root; yap(root.payload[0].payload[0].payload[0]); Foo foo; return foo; } void main() { auto foo = makeFoo(); writeln(foo.name); // Garbled output, then an exception } ----
Comment #3
by dlang-bot — 2019-05-25T05:31:59Z
dlang/dmd pull request #9853 "Fix issue 19825 - Memory corruption with lazy parameter" was merged into stable: - 7923db297e76946f003de080603c5ac1dfaca338 by سليمان السهمي (Suleyman Sahmi): Fix issue 19825
https://github.com/dlang/dmd/pull/9853