[Issue 18980] New: Typesafe variadic array functions cause memory corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 13 23:40:45 UTC 2018


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

          Issue ID: 18980
           Summary: Typesafe variadic array functions cause memory
                    corruption
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: mrjnewt at gmail.com

Created attachment 1703
  --> https://issues.dlang.org/attachment.cgi?id=1703&action=edit
Reproduction code

I've attached a simple D program that builds a complex JSONValue using several
helper functions with signatures like

JSONValue or(JSONValue[] conditions...) {}

I've found that the resulting programs have (sometimes) subtle memory
corruption issues.  To replicate, download the attached D file and compile &
run with:

dmd -run badness.d
dmd -O -inline -release -run badness.d

The issue manifests with optimizations on AND off, although generally
differently: sometimes with bad JSON output, other times with a memory
allocation failure.

My guess is that the arguments to these variadic array functions are being
stack allocated and passing out of scope.  If you put `.dup` on the two lines
indicated in the source, the problem is resolved.

--


More information about the Digitalmars-d-bugs mailing list